コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
ファイル: DecoratorCached.php プロジェクト: mufuphlex/cplt
 /**
  * @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;
 }
コード例 #4
0
ファイル: Cache.php プロジェクト: sibphp/sframe
 /**
  * 设置缓存
  *
  * @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;
 }
コード例 #5
0
ファイル: CacheLog.php プロジェクト: thumbtack/querycache
 /**
  * @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;
 }
コード例 #6
0
 /**
  * @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;
 }
コード例 #7
0
ファイル: Pages.php プロジェクト: tboothman/imdbphp
 protected function saveToCache($url, $page)
 {
     $this->cache->set($this->getCacheKey($url), $page);
 }
コード例 #8
0
ファイル: CacheProxy.php プロジェクト: staabm/thincache
 /**
  * (non-PHPdoc)
  * @see CacheInterface::set()
  */
 public function set($key, $value, $expire)
 {
     $this->proxyStore->set($key, $value, $expire);
     $this->backend->set($key, $value, $expire);
 }
コード例 #9
0
ファイル: NamespacedCache.php プロジェクト: kuria/cache
 public function set($key, $value, $ttl = 0, array $options = array())
 {
     return $this->wrappedCache->set($this->prefix . $key, $value, $ttl, $options);
 }
コード例 #10
0
ファイル: CacheInMemory.php プロジェクト: staabm/thincache
 /**
  * (non-PHPdoc)
  * @see Cache::set()
  */
 public function set($key, $value, $expire)
 {
     $this->init();
     return $this->backend->set($key, $value, $expire);
 }