Exemplo n.º 1
0
 /**
  * Generate exception based of memcached result code
  *
  * @param int $code
  * @return Exception\RuntimeException
  * @throws Exception\InvalidArgumentException On success code
  */
 protected function getExceptionByResultCode($code)
 {
     switch ($code) {
         case MemcachedResource::RES_SUCCESS:
             throw new Exception\InvalidArgumentException("The result code '{$code}' (SUCCESS) isn't an error");
         default:
             return new Exception\RuntimeException($this->memcached->getResultMessage());
     }
 }
Exemplo n.º 2
0
 /**
  * Get storage capacity.
  *
  * @param  array $options
  * @return array|boolean Capacity as array or false on failure
  *
  * @triggers getCapacity.pre(PreEvent)
  * @triggers getCapacity.post(PostEvent)
  * @triggers getCapacity.exception(ExceptionEvent)
  */
 public function getCapacity(array $options = array())
 {
     $args = new ArrayObject(array('options' => &$options));
     try {
         $eventRs = $this->triggerPre(__FUNCTION__, $args);
         if ($eventRs->stopped()) {
             return $eventRs->last();
         }
         $mem = array_pop($this->memcached->getStats());
         $result = array('free' => $mem['limit_maxbytes'] - $mem['bytes'], 'total' => $mem['limit_maxbytes']);
         return $this->triggerPost(__FUNCTION__, $args, $result);
     } catch (\Exception $e) {
         return $this->triggerException(__FUNCTION__, $args, $e);
     }
 }
Exemplo n.º 3
0
 public function testNoOptionsSetsDefaultServer()
 {
     $memcached = new Cache\Storage\Adapter\Memcached();
     $this->assertEquals($memcached->getOptions()->getServers(), array(array('127.0.0.1', 11211)));
 }
Exemplo n.º 4
0
 /**
  * @deprecated
  */
 public function testLibOptionSet()
 {
     $options = new Cache\Storage\Adapter\MemcachedOptions();
     $deprecated = false;
     set_error_handler(function () use(&$deprecated) {
         $deprecated = true;
     }, E_USER_DEPRECATED);
     $options->setLibOption('COMPRESSION', false);
     restore_error_handler();
     $this->assertTrue($deprecated, 'Missing deprecated error');
     $this->assertEquals($options->getResourceManager()->getLibOption($options->getResourceId(), \Memcached::OPT_COMPRESSION), false);
     $memcached = new Cache\Storage\Adapter\Memcached($options);
     $this->assertEquals($memcached->getOptions()->getLibOptions(), array(\Memcached::OPT_COMPRESSION => false));
 }
Exemplo n.º 5
0
 /**
  * GzEncodes an item for storage
  *
  * @param  string $key
  * @param  mixed $value
  * @return bool
  */
 public function setItem($key, $value)
 {
     return $this->storageInterface->setItem($key, gzencode($value));
 }
 /**
  * Remove an item
  *
  * @param string $key
  * @return bool
  */
 public function removeItem($key)
 {
     $this->setTags($key, []);
     // with tags
     return parent::removeItem($key);
 }
Exemplo n.º 7
0
 public function testNoOptionsSetsDefaultServer()
 {
     $memcached = new Cache\Storage\Adapter\Memcached();
     $expected = array(array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 0));
     $this->assertEquals($expected, $memcached->getOptions()->getServers());
 }