/**
  * {@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;
 }
Esempio n. 3
0
 /**
  * {@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;
 }