/** * {@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 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; }