/** * @param string $key * @param mixed $value * @param int $ttl * * @return bool */ public function setExpired($key, $value, $ttl = 0) { $item = $this->serializer->serialize(array('value' => $value, 'ttl' => $ttl ? (int) $ttl + time() : 0)); if (!file_put_contents($this->getFileName($key), $item)) { return false; } return true; }
/** * set cache-item by key => value + ttl * * @param string $key * @param mixed $value * @param int $ttl * * @return bool */ public function setItem($key, $value, $ttl = 0) { $storeKey = $this->calculateStoreKey($key); if ($this->adapter instanceof iAdapter && $this->serializer instanceof iSerializer) { $serialized = $this->serializer->serialize($value); if ($ttl) { return $this->adapter->setExpired($storeKey, $serialized, $ttl); } else { return $this->adapter->set($storeKey, $serialized); } } else { return false; } }