Example #1
0
 /**
  * Persists a cache item immediately.
  *
  * @param 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(CacheItemInterface $item)
 {
     if (!$item instanceof CacheItem) {
         return false;
     }
     // remove from queue
     if (isset($this->_queue[$item->getKey()])) {
         unset($this->_queue[$item->getKey()]);
     }
     /** @var CacheItem $cacheItem */
     $cacheItem = $item;
     // delete an expired item
     $expiry = $cacheItem->getExpiry();
     if ($expiry !== 0 && $expiry < time()) {
         $this->deleteItem($cacheItem->getKey());
         return true;
     }
     $this->_cache->set($item->getKey(), $item->get() === null ? new NullObject() : $item->get(), $expiry === 0 ? 0 : $expiry - time());
     return true;
 }
Example #2
0
 /**
  * @return int
  */
 public function clear()
 {
     return $this->cache->delete($this->key);
 }