/** * @param Config $config OPTIONAL override default config * @param LoggerInterface $logger OPTIONAL override default logger * @param CacheInterface $cache OPTIONAL override default cache */ public function __construct(Config $config = null, LoggerInterface $logger = null, CacheInterface $cache = null) { parent::__construct(); if ($config) { foreach ($config as $key => $value) { $this->{$key} = $value; } } $this->config = $config ?: $this; $this->logger = empty($logger) ? new Logger($this->debug) : $logger; $this->cache = empty($cache) ? new Cache($this->config, $this->logger) : $cache; $this->pages = new Pages($this->config, $this->cache, $this->logger); $this->cache->purge(); }
/** * Create autodisovery structure * Param use $string "%s_id" to access $name . "_id" column in $row->$name * @param \PDO $connection * @param CacheInterface $cache * @param string $foreign */ public function __construct(\PDO $connection, CacheInterface $cache = null, $foreign = '%s') { $this->connection = $connection; $this->cache = $cache; $this->foreign = $foreign; if ($cache) { $this->structure = $cache->load("structure"); } }
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); }
/** * @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; }
public function __construct(CacheInterface $cache, LoggerInterface $logger) { $this->cacheInterface = $cache; $this->logger = $logger; $this->cacheReady = $cache->cacheReady(); if (array_key_exists('jhm_disable_cache', $_COOKIE)) { $this->logger->log('DEBUG', 'jhm_disable_cache cookie detected; disabling cache engine.'); $this->cacheReady = false; $this->cacheInterface->clear(); } if (array_key_exists('cache-control', $_GET)) { $this->_cachecontrol(filter_var($_GET['cache-control'], FILTER_SANITIZE_STRING)); } }
/** * 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; }
/** * First tries to find the class in the cache. If the class is not found in the cache, then it tries to find it * by using the registered maps. * * @param string $class Name of the class you are trying to find. * * @return bool True is retuned if the class if found and loaded into memory. */ public function getClassFromCache($class) { // from cache if ($file = $this->cache->read($class)) { require $file; } // from disk if ($file = $this->findClass($class)) { $this->cache->save('wf.component.class_loader.' . $class, $file, 600, ['_wf', '_component', '_class_loader']); require $file; } }
/** * Retrieve response from cache if it exists otherwise make a GET request. * * @param string $endpoint Request endpoint. * @param string $root_property The theme/plugin slug or WordPress version. * * @return SSNepenthe\Soter\WPVulnDB\Response * * @throws \InvalidArgumentException When endpoint is not a string. * @throws \InvalidArgumentException When root_property is not a string. */ protected function get_and_cache($endpoint, $root_property) { if (!is_string($endpoint)) { throw new \InvalidArgumentException(sprintf('The endpoint parameter is required to be string, was: %s', gettype($endpoint))); } if (!is_string($root_property)) { throw new \InvalidArgumentException(sprintf('The root_property parameter is required to be string, was: %s', gettype($root_property))); } if ($this->cache->contains($endpoint)) { return new Response($this->cache->fetch($endpoint), $root_property); } $response = $this->http->get($endpoint); // @todo Filterable cache lifetime? $this->cache->save($endpoint, $response, 60 * 60 * 12); return new Response($response, $root_property); }
public function canFilter() { return $this->wrappedCache->canFilter(); }
public function cacheCheck($MatchString, CacheInterface $cache) { if (preg_match("#{$MatchString}#", $_SERVER['PHP_SELF']) === 1) { $cache->cacheCheck(); } }
protected function saveToCache($url, $page) { $this->cache->set($this->getCacheKey($url), $page); }
/** * Clear cache data * @return void */ public function reset() { $this->cache->remove($this->cacheId); }
public function supported() { return $this->backend->supported(); }
private function getCache($key) { return $this->cache->getCache($key); }
/** * @inheritdoc */ public function clear() { $start = microtime(true); $this->instance->clear(); $this->update_stats(__FUNCTION__, $start, ''); }
/** * Get the meta from the given key. * * @param string $type * * @param string $subtype * * @return MetaInterface|NULL */ public function getMeta($type, $subtype) { $this->refresh(); return $this->cache->getMeta($type, $subtype); }
/** * (non-PHPdoc) * @see Cache::delete() */ public function delete($key) { $this->init(); return $this->backend->delete($key); }
/** * 删除缓存 */ public function del($key) { $this->_store->del($key); }