/** * Here we pass in a cache key to be fetched from the cache. * A CacheItem object will be constructed and returned to us * * @param string $key The unique key of this item in the cache * * @return CacheItemInterface The newly populated CacheItem class representing the stored data in the cache */ public function getItem($key) { $item = new CacheItem($key); if (isset(static::$store[$key])) { $item->setValue(static::$store[$key]); } return $item; }
/** * Here we pass in a cache key to be fetched from the cache. * A CacheItem object will be constructed and returned to us * * @param string $key The unique key of this item in the cache * * @return CacheItemInterface The newly populated CacheItem class representing the stored data in the cache */ public function getItem($key) { $item = new CacheItem($key); if ($this->exists($key)) { $item->setValue(xcache_get($key)); } return $item; }
/** * Here we pass in a cache key to be fetched from the cache. * A CacheItem object will be constructed and returned to us * * @param string $key The unique key of this item in the cache * * @return CacheItemInterface The newly populated CacheItem class representing the stored data in the cache */ public function getItem($key) { $item = new CacheItem($key); if (isset($this->store[$key])) { $item->setValue($this->store[$key]); } return $item; }
/** * Here we pass in a cache key to be fetched from the cache. * A CacheItem object will be constructed and returned to us * * @param string $key The unique key of this item in the cache * * @return CacheItemInterface The newly populated CacheItem class representing the stored data in the cache */ public function getItem($key) { $this->connect(); $value = $this->driver->get($key); $item = new CacheItem($key); if ($value !== false) { $item->setValue($value); } return $item; }
/** * Here we pass in a cache key to be fetched from the cache. * A CacheItem object will be constructed and returned to us * * @param string $key The unique key of this item in the cache * * @return CacheItemInterface The newly populated CacheItem class representing the stored data in the cache */ public function getItem($key) { $this->connect(); $value = $this->driver->get($key); $code = $this->driver->getResultCode(); $item = new CacheItem($key); if ($code === \Memcached::RES_SUCCESS) { $item->setValue($value); } return $item; }
/** * Method to get a storage entry value from a key. * * @param string $key The storage entry identifier. * * @return CacheItemInterface * * @since 2.0 * @throws \RuntimeException */ public function getItem($key) { if (!$this->exists($key)) { return new CacheItem($key); } $resource = @fopen($this->fetchStreamUri($key), 'rb'); if (!$resource) { throw new \RuntimeException(sprintf('Unable to fetch cache entry for %s. Connot open the resource.', $key)); } // If locking is enabled get a shared lock for reading on the resource. if ($this->options['file_locking'] && !flock($resource, LOCK_SH)) { throw new \RuntimeException(sprintf('Unable to fetch cache entry for %s. Connot obtain a lock.', $key)); } $data = stream_get_contents($resource); // If locking is enabled release the lock on the resource. if ($this->options['file_locking'] && !flock($resource, LOCK_UN)) { throw new \RuntimeException(sprintf('Unable to fetch cache entry for %s. Connot release the lock.', $key)); } fclose($resource); $item = new CacheItem($key); if ($this->denyAccess) { $data = substr($data, strlen($this->options['deny_code'])); } $item->setValue($data); return $item; }