Example #1
0
File: Redis.php Project: itkg/core
 /**
  * Set a value into the cache
  *
  * @param \Itkg\Core\CacheableInterface $item
  *
  * @return void
  */
 public function set(CacheableInterface $item)
 {
     $this->getConnection()->set($item->getHashKey(), $item->getDataForCache());
     if (null !== $item->getTtl()) {
         $this->getConnection()->expire($item->getHashKey(), $item->getTtl());
     }
 }
Example #2
0
 /**
  * Set a value into the cache
  *
  * @param CacheableInterface $item
  *
  * @return void
  */
 public function set(CacheableInterface $item)
 {
     $this->connection->set($item->getHashKey(), $item->getDataForCache(), $item->getTtl());
 }
Example #3
0
 /**
  * Get value from cache
  * Must return false when cache is expired or invalid
  *
  * @param \Itkg\Core\CacheableInterface $item
  *
  * @return mixed
  */
 public function get(CacheableInterface $item)
 {
     $targetFile = $this->getTargetFile($item->getHashKey());
     $return = false;
     if (file_exists($targetFile)) {
         if ($item->getTtl() > 0 && filemtime($targetFile) + $item->getTtl() < time()) {
             $this->remove($item);
         } else {
             $return = unserialize(file_get_contents($targetFile, false, null, strlen(self::STR_PREFIX)));
         }
     }
     return $return;
 }
Example #4
0
 /**
  * Set a value into the cache
  *
  * @param \Itkg\Core\CacheableInterface $item
  *
  * @return void
  */
 public function set(CacheableInterface $item)
 {
     $this->provider->save($item->getHashKey(), $item->getDataForCache(), $item->getTtl());
 }