/** * @throws Behance\NBD\Cache\Exceptions\SystemRequirementException when memcache extension is not loaded * * @param Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * @param Memcache $instance */ public function __construct(EventDispatcherInterface $event_dispatcher = null, \Memcache $instance = null) { $this->_connection = $instance ?: new \Memcache(); // Really unfortunate to have to do this $this->_memcache_get_requires_filler = (new \ReflectionMethod('Memcache', 'get'))->getNumberOfParameters() > 1; parent::__construct($event_dispatcher); }
/** * {@inheritDoc} */ protected function _execute(\Closure $action, $operation, $key_or_keys, $mutable = false, $value = null) { $result = parent::_execute($action, $operation, $key_or_keys, $mutable, $value); // Adapter connection itself will only report correctly when not currently buffering results if (!$this->isBuffering()) { $code = $this->_connection->getResultCode(); if ($code !== \Memcached::RES_SUCCESS) { $this->_handleFailure($this->_connection->getResultMessage(), null, null, $code); } } // if !isBuffering return $result; }
/** * {@inheritDoc} * * @link https://github.com/phpredis/phpredis#class-redisexception */ protected function _execute(\Closure $action, $operation, $key_or_keys, $mutable = false, $value = null) { // Redis may throw an exception for any connectivity error, unlike memcache and memcached. Suppress exception, log, and return false $protected_action = function () use($action) { try { return $action(); } catch (\RedisException $e) { $this->_handleFailure($e->getMessage(), null, null, $e->getCode()); return false; } }; // protected_action return parent::_execute($protected_action, $operation, $key_or_keys, $mutable, $value); }