/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }