/** * @param SystemEvent $evt * @throws Exception * * @return int The number of equal-hashed events */ public function store(SystemEvent $evt) { if (empty($evt->hash)) { throw new Exception("Hash is not expected to be empty!"); } // work on a defensive copy, so we won't influence the given arg $evt2Store = clone $evt; if ($evt2Store->origin instanceof RequestExceptionEvent) { // wrap exception to prevent endless-recursion caused by args in stacktraces $evt2Store->origin->exception = SerializableException::fromException($evt2Store->origin->exception); } $events = $this->findByHash($evt2Store->hash); // make sure we only hold at most X event-occurences, but keep the oldest $maxOccurences = 5; if (count($events) > $maxOccurences) { $oldest = $events[0]; $events = array_slice($events, -($maxOccurences - 1)); $events[0] = $oldest; } $events[] = $evt2Store; // events which don't happen at least once per X hours, will be dropped $this->dataStore->set(self::CACHE_NAMESPACE . $evt2Store->hash, $events, strtotime("+2 hours")); if ($this->dataStatistics->supported()) { // we remember how often an error occured a bit longer than the actual even-data // because this info might help us later on to decide which events are more important than others. return $this->dataStatistics->increment(self::CACHE_NAMESPACE . $evt2Store->hash, 1, strtotime("+3 hours")); } // when APC is not supported, return approx. value return count($events); }
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; }
/** * 设置缓存 * * @param string $key * @param mixed $data_source 回调或默认 * @param int $expire 设置缓存过期时间 * @return mixed */ public function set($key, $data_source, $expire = null, $compressed = false) { if (is_callable($data_source)) { $data = $data_source(); } else { $data = $data_source; } if (!empty($data)) { $key = strtolower($key); $expire = $expire === null ? $this->_default_expire : $expire; $this->_store->set($key, $data, $expire, $compressed); } return $data; }
/** * @inheritdoc */ public function set($key_or_map, $val = null, $ttl = null) { $start = microtime(true); $res = $this->instance->set($key_or_map, $val, $ttl); $keys = is_string($key_or_map) ? [$key_or_map] : array_keys($key_or_map); $this->update_stats(__FUNCTION__, $start, $keys); return $res; }
/** * @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; }
protected function saveToCache($url, $page) { $this->cache->set($this->getCacheKey($url), $page); }
/** * (non-PHPdoc) * @see CacheInterface::set() */ public function set($key, $value, $expire) { $this->proxyStore->set($key, $value, $expire); $this->backend->set($key, $value, $expire); }
public function set($key, $value, $ttl = 0, array $options = array()) { return $this->wrappedCache->set($this->prefix . $key, $value, $ttl, $options); }
/** * (non-PHPdoc) * @see Cache::set() */ public function set($key, $value, $expire) { $this->init(); return $this->backend->set($key, $value, $expire); }