/** * Optimize by factor on a success _RESULT_ * * @param PostEvent $event * @return void */ public function optimizeByFactor(PostEvent $event) { $storage = $event->getStorage(); if (!$storage instanceof OptimizableInterface) { return; } $factor = $this->getOptions()->getOptimizingFactor(); if ($factor && mt_rand(1, $factor) == 1) { $storage->optimize(); } }
/** * Clear expired items by factor after writing new item(s) * * @param PostEvent $event * @return void */ public function clearExpiredByFactor(PostEvent $event) { $storage = $event->getStorage(); if (!$storage instanceof ClearExpiredInterface) { return; } $factor = $this->getOptions()->getClearingFactor(); if ($factor && mt_rand(1, $factor) == 1) { $storage->clearExpired(); } }
/** * Clear storage by factor on a success _RESULT_ * * @param PostEvent $event * @return void */ public function clearByFactor(PostEvent $event) { $options = $this->getOptions(); $factor = $options->getClearingFactor(); if ($factor && $event->getResult() && mt_rand(1, $factor) == 1) { $params = $event->getParams(); if ($options->getClearByNamespace()) { $event->getStorage()->clearByNamespace(Adapter::MATCH_EXPIRED, $params['options']); } else { $event->getStorage()->clear(Adapter::MATCH_EXPIRED, $params['options']); } } }
/** * Optimize by factor on a success _RESULT_ * * @param PostEvent $event * @return void */ public function optimizeByFactor(PostEvent $event) { $factor = $this->getOptions()->getOptimizingFactor(); if ($factor && $event->getResult() && mt_rand(1, $factor) == 1) { $params = $event->getParams(); $event->getStorage()->optimize($params['options']); } }