Ejemplo n.º 1
0
 /**
  * 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();
     }
 }
Ejemplo n.º 2
0
 /**
  * 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();
     }
 }
Ejemplo n.º 3
0
 /**
  * On get capabilities
  *
  * @param  PostEvent $event
  * @return void
  */
 public function onGetCapabilitiesPost(PostEvent $event)
 {
     $baseCapabilities = $event->getResult();
     $index = spl_object_hash($baseCapabilities);
     if (!isset($this->capabilities[$index])) {
         $this->capabilities[$index] = new Capabilities(new stdClass(), array('supportedDatatypes' => array('NULL' => true, 'boolean' => true, 'integer' => true, 'double' => true, 'string' => true, 'array' => true, 'object' => 'object', 'resource' => false)), $baseCapabilities);
     }
     $event->setResult($this->capabilities[$index]);
 }
Ejemplo n.º 4
0
 /**
  * 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']);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * 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']);
     }
 }
Ejemplo n.º 6
0
 /**
  * Constructor
  *
  * Accept a target and its parameters.
  *
  * @param  string $name
  * @param  StorageInterface $storage
  * @param  ArrayObject $params
  * @param  mixed $result
  * @param  Exception $exception
  */
 public function __construct($name, StorageInterface $storage, ArrayObject $params, &$result, Exception $exception)
 {
     parent::__construct($name, $storage, $params, $result);
     $this->setException($exception);
 }