Example #1
0
 /**
  * @param \Psr\Cache\CacheItemInterface $item
  * @return mixed
  * @throws \InvalidArgumentException
  */
 protected function driverWrite(CacheItemInterface $item)
 {
     /**
      * Check for Cross-Driver type confusion
      */
     if ($item instanceof Item) {
         $ttl = $item->getExpirationDate()->getTimestamp() - time();
         return zend_shm_cache_store($item->getKey(), $this->driverPreWrap($item), $ttl > 0 ? $ttl : 0);
     } else {
         throw new \InvalidArgumentException('Cross-Driver type confusion detected');
     }
 }
Example #2
0
 /**
  * @param \Psr\Cache\CacheItemInterface $item
  * @return mixed
  * @throws \InvalidArgumentException
  */
 protected function driverWrite(CacheItemInterface $item)
 {
     /**
      * Check for Cross-Driver type confusion
      */
     if ($item instanceof Item) {
         $ttl = $item->getExpirationDate()->getTimestamp() - time();
         // Memcache will only allow a expiration timer less than 2592000 seconds,
         // otherwise, it will assume you're giving it a UNIX timestamp.
         if ($ttl > 2592000) {
             $ttl = time() + $ttl;
         }
         return $this->instance->set($item->getKey(), $this->driverPreWrap($item), $ttl);
     } else {
         throw new \InvalidArgumentException('Cross-Driver type confusion detected');
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function save(CacheItemInterface $item)
 {
     $timeToLive = 0;
     if ($item instanceof HasExpirationDateInterface) {
         if (null !== ($expirationDate = $item->getExpirationDate())) {
             $timeToLive = $expirationDate->getTimestamp() - time();
         }
     }
     return $this->cache->save($item->getKey(), $item, $timeToLive);
 }
 /**
  * {@inheritdoc}
  */
 public function save(CacheItemInterface $item)
 {
     if ($item instanceof TaggableItemInterface) {
         $key = $item->getTaggedKey();
     } else {
         $key = $item->getKey();
     }
     $timeToLive = null;
     if ($item instanceof HasExpirationDateInterface) {
         if (null !== ($expirationDate = $item->getExpirationDate())) {
             $timeToLive = $expirationDate->getTimestamp() - time();
         }
     }
     return $this->storeItemInCache($key, $item, $timeToLive);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function save(CacheItemInterface $item)
 {
     $data = "{$item->get()};{$item->getExpirationDate()->format('Y-m-d H:i:s')}";
     file_put_contents("{$this->cacheFolder}/{$item->getKey()}.txt", $data);
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function save(CacheItemInterface $item)
 {
     $timeToLive = null;
     if ($item instanceof HasExpirationDateInterface) {
         if (null !== ($expirationDate = $item->getExpirationDate())) {
             $timeToLive = $expirationDate->getTimestamp() - time();
             if ($timeToLive < 0) {
                 return $this->deleteItem($item->getKey());
             }
         }
     }
     try {
         return $this->storeItemInCache($item, $timeToLive);
     } catch (\Exception $e) {
         $this->handleException($e, __FUNCTION__);
     }
 }
 /**
  * @param CacheItem $item
  * {@inheritDoc}
  */
 public function save(CacheItemInterface $item)
 {
     return $this->cache->save($item->getKey(), ['value' => $item->get(), 'expiration' => $item->getExpirationDate()]);
 }