Beispiel #1
0
 /**
  * Reads the specified item from the cache or generate it.
  * @param  mixed key
  * @param  callable
  * @return mixed|NULL
  */
 public function load($key, $fallback = NULL)
 {
     $data = $this->storage->read($this->generateKey($key));
     if ($data === NULL && $fallback) {
         return $this->save($key, new Callback($fallback));
     }
     return $data;
 }
Beispiel #2
0
	/**
	 * Reads the specified item from the cache or generate it.
	 * @param  mixed key
	 * @param  callable
	 * @return mixed|NULL
	 */
	public function load($key, $fallback = NULL)
	{
		$data = $this->storage->read($this->namespace . md5(is_scalar($key) ? $key : serialize($key)));
		if ($data === NULL && $fallback) {
			return $this->save($key, callback($fallback));
		}
		return $data;
	}
Beispiel #3
0
 /**
  * Exists item in cache? (\ArrayAccess implementation).
  * @param  string key
  * @return bool
  * @throws InvalidArgumentException
  */
 public function offsetExists($key)
 {
     if (!is_string($key)) {
         throw new InvalidArgumentException("Cache key name must be string, " . gettype($key) . " given.");
     }
     $this->key = $key;
     $this->data = $this->storage->read($this->namespace . $key);
     return $this->data !== NULL;
 }
Beispiel #4
0
 /**
  * Exists item in cache? (\ArrayAccess implementation).
  * @param  string key
  * @return bool
  * @throws InvalidArgumentException
  */
 public function offsetExists($key)
 {
     if (!is_string($key) && !is_int($key)) {
         throw new InvalidArgumentException("Cache key name must be string or integer, " . gettype($key) . " given.");
     }
     $this->key = (string) $key;
     $this->data = $this->storage->read($this->namespace . self::NAMESPACE_SEPARATOR . $key);
     return $this->data !== NULL;
 }