Example #1
0
 /**
  * Class constructor.
  *
  * @param array                    $options Initial options for the cache adapter:
  *                                          - persistent_id string Optional persistent key
  *                                          - servers array The memcached servers to add
  *                                          - options array The memcached options to set
  * @param string                   $context An optional cache context use as prefix key
  * @param \Psr\Log\LoggerInterface $logger  An optional logger
  *
  * @throws \BackBee\Cache\Exception\CacheException Occurs if Memcached extension is not available.
  */
 public function __construct(array $options = array(), $context = null, LoggerInterface $logger = null)
 {
     if (false === extension_loaded('memcached')) {
         throw new CacheException('Memcached extension is not loaded');
     }
     if (true === array_key_exists('persistent_id', $options)) {
         $this->_cache = new \Memcached($options['persistent_id']);
     } else {
         $this->_cache = new \Memcached();
     }
     parent::__construct($options, $context, $logger);
     if (null !== $this->getContext()) {
         $this->setOption(\Memcached::OPT_PREFIX_KEY, md5($this->getContext()));
     }
     if (false === is_array($this->_instance_options['options'])) {
         throw new CacheException('Memcached adapter: memcached options is not an array.');
     }
     $this->_instance_options['options'] = array_merge($this->_cache_options, $this->_instance_options['options']);
     foreach ($this->_instance_options['options'] as $option => $value) {
         $this->setOption($option, $value);
     }
     if (null !== $this->_instance_options['compression']) {
         $this->setOption(\Memcached::OPT_COMPRESSION, $this->_instance_options['compression']);
     }
     if (false === is_array($this->_instance_options['servers'])) {
         throw new CacheException('Memcached adapter: memcached servers is not an array.');
     }
     $this->addServers($this->_instance_options['servers']);
 }
Example #2
0
 /**
  * Class constructor.
  *
  * @param array                    $options Initial options for the cache adapter:
  *                                          - persistent_id string Optional persistent key
  *                                          - servers array The Memcache servers to add
  *                                          - options array The Memcache options to set
  * @param string                   $context An optional cache context use as prefix key
  * @param \Psr\Log\LoggerInterface $logger  An optional logger
  *
  * @throws \BackBee\Cache\Exception\CacheException Occurs if Memcache extension is not available.
  */
 public function __construct(array $options = array(), $context = null, LoggerInterface $logger = null)
 {
     if (false === extension_loaded('Memcache')) {
         throw new CacheException('Memcache extension is not loaded');
     }
     $this->_cache = new \Memcache();
     parent::__construct($options, $context, $logger);
     if (true === $this->_instance_options['compression']) {
         $this->compression = MEMCACHE_COMPRESSED;
     }
     if (false === is_array($this->_instance_options['servers'])) {
         throw new CacheException('Memcache adapter: Memcache servers is not an array.');
     }
     $this->addServers($this->_instance_options['servers']);
 }