/** * 获取缓存 * 如果缓存不存在,可以通过回调函数获取数据源设置到缓存里 * * @param string $key * @param mixed $data_source 回调或默认 * @param int $expire 设置缓存过期时间 * @return mixed */ public function get($key, $data_source = null, $expire = null, $compressed = false) { $key = strtolower($key); $data = $this->_store->get($key); if (null === $data) { $data = $this->set($key, $data_source, $expire, $compressed); } return $data; }
public function setFile($file, $fileContent) { $file = $this->cacheDirectory->getRelativePathTo($file); $hash = $this->calcHash($fileContent); if ($this->isDryRun && $this->cache->has($file) && $this->cache->get($file) !== $hash) { $this->cache->clear($file); return; } $this->cache->set($file, $hash); }
/** * (non-PHPdoc) * @see CacheInterface::get() */ public function get($key, $default = null) { // lookup proxyStore for fast exit $val = $this->proxyStore->get($key, 'clx-cache-null'); if ($val !== 'clx-cache-null') { return $val; } // no result in the proxyStore -> retrieve value from backend and // store in the proxyStore to serve a possible second call from the proxyStore $val = $this->backend->get($key, $default); $this->proxyStore->set($key, $val, $this->proxyExpireTime); return $val; }
/** * @param string $term * @param string $namespace * @return array */ public function find($term, $namespace = '') { $key = $this->makeKey($term, $namespace); $cache = $this->cache->get($key); if ($cache !== null) { return $cache; } $result = $this->container->find($term, $namespace); if (!empty($result)) { $this->cache->set($key, $result); } return $result; }
/** * Returns all available detail data for SystemEvents with the given hash. * * @param string $hash * @return SystemEvent[] */ public function findByHash($hash) { if (empty($hash)) { throw new Exception("Hash is not expected to be empty!"); } return $this->dataStore->get(self::CACHE_NAMESPACE . $hash, array()); }
private function request($call, $otherQueries = false, $static = false) { //format the full URL $url = $this->format_url($call, $otherQueries); //caching if ($this->cache !== null && $this->cache->has($url)) { $result = $this->cache->get($url); } else { // Check rate-limiting queues if this is not a static call. if (!$static) { $this->updateLimitQueue($this->longLimitQueue, self::LONG_LIMIT_INTERVAL, self::RATE_LIMIT_LONG); $this->updateLimitQueue($this->shortLimitQueue, self::SHORT_LIMIT_INTERVAL, self::RATE_LIMIT_SHORT); } //call the API and return the result $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $result = curl_exec($ch); $this->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($this->responseCode == 200) { if ($this->cache !== null) { $this->cache->put($url, $result, self::CACHE_LIFETIME_MINUTES * 60); } if (self::DECODE_ENABLED) { $result = json_decode($result, true); } } else { throw new Exception(self::$errorCodes[$this->responseCode]); } } return $result; }
/** * @param array $pipeline * @param array $op * @param null $op1 * @return array */ public function aggregate($pipeline, $op = null, $op1 = null) { $op = $op ?: []; if (is_array($op) && isset($op['cache']) && $op['cache'] === false) { unset($op['cache']); return parent::aggregate($pipeline, $op); } if (!isset($pipeline[0])) { $pipeline = func_get_args(); } $hash = $this->hash($pipeline); $result = $this->cache->get($hash); if (!$result) { $result = parent::aggregate($pipeline, $op); $this->cache->set($hash, $result, $this->getCacheTime($op)); } return $result; }
/** * @inheritdoc */ public function get($key) { $start = microtime(true); $res = $this->instance->get($key); $hit = $res->hit() ? 1 : 0; $miss = $hit ? 0 : 1; $this->update_stats(__FUNCTION__, $start, $key, $hit, $miss); return $res; }
protected function getFromCache($url) { return $this->cache->get($this->getCacheKey($url)); }
public function get($key, array $options = array()) { return $this->wrappedCache->get($this->prefix . $key, $options); }
/** * (non-PHPdoc) * @see Cache::get() */ public function get($key, $default = null) { $this->init(); return $this->backend->get($key, $default); }