Esempio n. 1
0
 /**
  * constructor
  *
  * @param array $options        associative array of cache driver options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('memcache')) {
         throw new Doctrine_Cache_Exception('In order to use Memcache driver, the memcache extension must be loaded.');
     }
     parent::__construct($options);
     if (isset($options['servers'])) {
         $value = $options['servers'];
         if (isset($value['host'])) {
             // in this case, $value seems to be a simple associative array (one server only)
             $value = array(0 => $value);
             // let's transform it into a classical array of associative arrays
         }
         $this->setOption('servers', $value);
     }
     $this->_memcache = new Memcache();
     foreach ($this->_options['servers'] as $server) {
         if (!array_key_exists('persistent', $server)) {
             $server['persistent'] = true;
         }
         if (!array_key_exists('port', $server)) {
             $server['port'] = 11211;
         }
         $this->_memcache->addServer($server['host'], $server['port'], $server['persistent']);
     }
 }
Esempio n. 2
0
 /**
  * constructor
  * 
  * @param array $options    associative array of cache driver options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('apc')) {
         throw new Doctrine_Cache_Exception('The apc extension must be loaded for using this backend !');
     }
     parent::__construct($options);
 }
Esempio n. 3
0
 /**
  * constructor
  * 
  * @param array $options        associative array of cache driver options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('xcache')) {
         throw new Doctrine_Cache_Exception('In order to use Xcache driver, the xcache extension must be loaded.');
     }
     parent::__construct($options);
 }
 /**
  * constructor
  *
  * @param array $options        associative array of cache driver options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     if (isset($options['rediska'])) {
         if ($options['rediska'] instanceof Rediska) {
             $this->_rediska = $options['rediska'];
         } else {
             throw new Doctrine_Cache_Exception('The rediska instance supplied to Doctrine_Cache_Redis is not a Rediska object.');
         }
     } else {
         $instance = $this->getOption('instance', 'default');
         $this->_rediska = sfRediska::getInstance($instance);
     }
 }
Esempio n. 5
0
 /**
  * constructor
  *
  * @param array $options        associative array of cache driver options
  * @throws Doctrine_Cache_Exception
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('memcached')) {
         throw new Doctrine_Cache_Exception('In order to use Memcached driver, the memcached extension must be loaded.');
     }
     parent::__construct($options);
     if (isset($options['servers'])) {
         $value = $options['servers'];
         if (isset($value['host'])) {
             // in this case, $value seems to be a simple associative array (one server only)
             $value = array(0 => $value);
             // let's transform it into a classical array of associative arrays
         }
         $this->setOption('servers', $value);
     }
     if (!array_key_exists('persistent', $options)) {
         $this->_memcached = new Memcached();
     } else {
         if (!array_key_exists('persistent_id', $options)) {
             throw new Doctrine_Cache_Exception('In order to use a persistent connection, a "persistent_id" option must be set.');
         }
         $this->_memcached = new Memcached($options['persistent_id']);
     }
     $this->_memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
     if (isset($this->_options['compression']) && true == $this->_options['compression']) {
         $this->_memcached->setOption(Memcached::OPT_COMPRESSION, true);
     } else {
         $this->_memcached->setOption(Memcached::OPT_COMPRESSION, false);
     }
     if (isset($this->_options['binaryprotocol']) && true == $this->_options['binaryprotocol']) {
         $this->_memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
     } else {
         $this->_memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, false);
     }
     foreach ($this->_options['servers'] as $server) {
         if (!array_key_exists('port', $server)) {
             $server['port'] = 11211;
         }
         if (!array_key_exists('weight', $server)) {
             $server['weight'] = 0;
         }
         $this->_memcached->addServer($server['host'], $server['port'], $server['weight']);
     }
 }