Ejemplo n.º 1
0
	/**
	 * Retrieves the specified item from the cache or NULL if the key is not found (\ArrayAccess implementation).
	 * @param  mixed key
	 * @return mixed|NULL
	 * @throws \InvalidArgumentException
	 */
	public function offsetGet($key)
	{
		$key = is_scalar($key) ? (string) $key : serialize($key);
		if ($this->key === $key) {
			return $this->data;
		}
		$this->key = $key;
		$this->data = $this->storage->read($this->namespace . md5($key));
		return $this->data;
	}
Ejemplo n.º 2
0
 /**
  * Retrieves the specified item from the cache or NULL if the key is not found (\ArrayAccess implementation).
  * @param  string key
  * @return mixed|NULL
  * @throws \InvalidArgumentException
  */
 public function offsetGet($key)
 {
     if (!is_string($key) && !is_int($key)) {
         throw new \InvalidArgumentException("Cache key name must be string or integer, " . gettype($key) . " given.");
     }
     $key = (string) $key;
     if ($this->key === $key) {
         return $this->data;
     }
     $this->key = $key;
     $this->data = $this->storage->read($this->namespace . self::NAMESPACE_SEPARATOR . $key);
     return $this->data;
 }