Exemplo n.º 1
0
 /**
  * Set (save) the item back to the cache pool.
  * @param mixed $value The unserialized value to store.
  * @param mixed $ttl This may be NULL to mean that it will fall back to
  * getDefaultExpireTime(), if that is not overriden then the item will
  * never expire. If it's and int it will be used as the number of seconds
  * from now until the item expire. Finally you can specify a \DateTime for
  * an absolute expire time.
  * @return TRUE on success, FALSE otherwise.
  */
 public function set($value = null, $ttl = null)
 {
     $this->value = $value;
     if (null === $ttl) {
         $expireTime = $this->pool->getDefaultExpireTime();
     } elseif ($ttl instanceof \DateTime) {
         $expireTime = $ttl;
     } elseif (is_int($ttl)) {
         $expireTime = new \DateTime("+{$ttl} second");
     } else {
         throw new InvalidArgumentException("Invalid argument for TTL.");
     }
     // update the isHit cache
     $this->isHit = true;
     // handle through the pool implementation
     return $this->pool->getAdapter()->set($this->key, $this->value, $expireTime);
 }
Exemplo n.º 2
0
 /**
  * Set (save) the item back to the cache pool.
  * @param mixed $value The unserialized value to store.
  * @param mixed $ttl This may be NULL to mean that it will fall back to
  * getDefaultExpireTime(), if that is not overriden then the item will
  * never expire. If it's and int it will be used as the number of seconds
  * from now until the item expire. Finally you can specify a \DateTime for
  * an absolute expire time.
  * @param bool $shouldNotBeEmpty (true) If set to false, then empty value will be treated as error
  * @throws InvalidArgumentException when TTL isn't a valid value
  * @return TRUE on success, FALSE otherwise.
  */
 public function set($value = null, $ttl = null, $shouldNotBeEmpty = false)
 {
     if ($shouldNotBeEmpty && empty($value)) {
         // log error
         $logger = $this->pool->getLogger();
         if (isset($logger)) {
             $logger->alert('Caching empty value - [' . get_class($this->pool) . ':' . $this->key . ']', array('pool' => get_class($this->pool), 'key' => $this->key, 'value' => $value, 'request_uri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null));
         }
     }
     $this->value = $value;
     if (null === $ttl) {
         $expireTime = $this->pool->getDefaultExpireTime();
     } elseif ($ttl instanceof \DateTime) {
         $expireTime = $ttl;
     } elseif (is_int($ttl)) {
         $expireTime = new \DateTime("+{$ttl} second");
     } else {
         throw new InvalidArgumentException("Invalid argument for TTL.");
     }
     // update the isHit cache
     $this->isHit = true;
     // handle through the pool implementation
     return $this->pool->getAdapter()->set($this->key, $this->value, $expireTime);
 }