/** * {@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 __invoke(CachePoolInterface $cache, $stage, CacheItemInterface $item = null) { if ($item instanceof CacheItemInterface) { if ($stage === ExtensionStage::STAGE_POST_GET) { if ($item->isHit()) { $res = @unserialize($item->get()); } } else { $res = @serialize($item->get()); } if (isset($res)) { if ($res === false) { return $this->falseAndSetError(Message::get(Message::CACHE_FAIL_SERIALIZE, $item->getKey()), Message::CACHE_FAIL_SERIALIZE); } $item->set($res); } } return true; }
/** * {@inheritDoc} */ public function __invoke(CachePoolInterface $cache, $stage, CacheItemInterface $item = null) { if ($item instanceof CacheItemInterface) { if ($stage === ExtensionStage::STAGE_POST_GET) { if ($item->isHit()) { $fnc = $this->decrypt; $res = $fnc($item->get()); } } else { $fnc = $this->encrypt; $res = $fnc($item->get()); } if (isset($res)) { // encrypt/decrypt failed if ($res === false) { return $this->falseAndSetError(Message::get(Message::CACHE_FAIL_ENCRYPT, $item->getKey()), Message::CACHE_FAIL_ENCRYPT); } // set to new string value $item->set($res); } } return true; }