/** * Persists a cache item immediately. * * @param \Psr\Cache\CacheItemInterface $item * The cache item to save. * * @return bool * True if the item was successfully persisted. False if there was an error. */ public function save(\Psr\Cache\CacheItemInterface $item) { // Gets the filename $file = $item->filename($item->getKey()); // Checks if the file write failes and serializes the value if (!file_put_contents($file, serialize($item->getValue()))) { return false; } $file = $item->filename($item->getKey(), 'expiration'); // Checks if the file write failes and serializes the value if (!file_put_contents($file, serialize($item->expiration))) { return false; } return true; }
/** * {@inheritDoc} */ public function save(CacheItemInterface $item) { $expiresAt = $item->getExpiresAt(); $this->cache->save($item->getKey(), $item->getValue(), null === $expiresAt ? 0 : $expiresAt->getTimestamp() - time()); return $this; }