/** * {@inheritDoc} */ public function __invoke(CachePoolInterface $cache, $stage, CacheItemInterface $item = null) { if (rand(1, $this->divisor) <= $this->probability) { // log message $cache->log('info', Message::get(Message::CACHE_GARBAGE_COLLECT, date("Y-m-d H:i:s"))); // purge those staled $cache->getDriver()->purge($this->max_lifetime); } // always true return true; }
/** * {@inheritDoc} */ public function __invoke(CachePoolInterface $cache, $stage, CacheItemInterface $item = null) { // 100/1000 (10%) chances to commit if (rand(1, $this->divisor) <= $this->probability) { // log message $cache->log('notice', Message::get(Message::CACHE_COMMIT_DEFERRED)); // commit deferred $cache->getDriver()->commit(); } // always return true return true; }
/** * {@inheritDoc} */ public function __invoke(CachePoolInterface $cache, $stage, CacheItemInterface $item = null) { if ($item instanceof CacheItemInterface && $item->isHit()) { // time left $left = $item->getExpiration()->getTimestamp() - time(); if ($left < $this->time_left && rand(1, $this->divisor) <= $this->probability) { // log message $cache->log('notice', Message::get(Message::CACHE_STAMPEDE_EXT, $item->getKey())); // revert to miss return $item->setHit(false); } } return true; }
/** * {@inheritDoc} */ public function isHit() { if (!is_bool($this->hit)) { // before has if (!$this->cache->runExtensions(ES::STAGE_PRE_HAS, $this)) { return $this->setHit(false); } $this->expire = $this->cache->getDriver()->has($this->key); $this->hit = $this->expire < time() ? false : true; // after has if (!$this->cache->runExtensions(ES::STAGE_POST_HAS, $this)) { return $this->setHit(false); } } return $this->hit; }
/** * Clear by tags * * @param CachePoolInterface $cache * @param string $tag tag * @return bool * @access public */ public function clearByTag(CachePoolInterface $cache, $tag) { // get tagItem for $tag $tagKey = $this->getTagKey($tag); $tagItem = $cache->getItem($tagKey); // read array of keys from $tagItem if ($tagItem->isHit()) { $keyArray = $tagItem->get(); foreach (array_keys($keyArray) as $key) { if ($cache->deleteItem($key)) { unset($keyArray[$key]); } } // get error if (count($keyArray)) { $this->setError($cache->getError(), $cache->getErrorCode()); } // update tagItem $tagItem->set($keyArray); $tagItem->expiresAfter($this->tag_life); // one year $cache->save($tagItem); if (count($keyArray)) { return false; } } return $this->trueAndFlushError(); }