Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->options['cache_dir'] = '/tmp/cache';
     $this->options = $options + $this->options;
     $this->options['cache_dir'] = rtrim($this->options['cache_dir'], '\\/');
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('xcache')) {
         throw new CacheException('The xcache extension must be loaded.');
     }
     parent::__construct($options);
 }
Ejemplo n.º 3
0
 /**
  * Constructor
  *
  * @param array $options
  * @throws CacheException
  */
 public function __construct($options = array())
 {
     if (!extension_loaded("yac")) {
         throw new CacheException('extension yac is not exist!');
     }
     parent::__construct($options);
     $name = isset($this->options['name']) ? $this->options['name'] : 'yaf-cache';
     $this->conn = new \Yac($name);
 }
Ejemplo n.º 4
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded("memcache")) {
         throw new CacheException('extension memcache is not exist!');
     }
     parent::__construct($options);
     $this->conn = new \Memcache();
     foreach ($this->options['servers'] as $server) {
         call_user_func_array(array($this->conn, 'addServer'), $server);
     }
 }
Ejemplo n.º 5
0
 /**
  * Constructor
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     if (!extension_loaded("memcached")) {
         throw new CacheException('extension memcached is not exist!');
     }
     parent::__construct($options);
     if (isset($this->options['persistent'])) {
         $this->conn = new \Memcached($this->options['persistent']);
     } else {
         $this->conn = new \Memcached();
     }
     $this->conn->addServers($this->options['servers']);
 }
Ejemplo n.º 6
0
 /**
  * Constructor
  *
  * @param array $options
  * @throws CacheException
  */
 public function __construct($options = array())
 {
     if (!extension_loaded("redis")) {
         throw new CacheException('extension redis is not exist!');
     }
     parent::__construct($options);
     $this->conn = new \Redis();
     if (empty($this->options['persistent'])) {
         $this->conn->connect($this->options['host'], $this->options['port'], $this->options['timeout']);
     } else {
         $this->conn->pconnect($this->options['host'], $this->options['port'], $this->options['timeout']);
     }
     foreach ($this->optionKeys as $key) {
         if (isset($this->options[$key])) {
             $this->conn->setOption($key, $this->options[$key]);
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Converts this data to a string that can output. This is not a hash
  * key or a serialization, but an actual render for humans.
  *
  * @throws Exceptions\NotCachedException
  */
 public function stringify(CacheAbstract $c, $recurse = true)
 {
     $retval = [];
     foreach ($this->data as $item) {
         if ($item['type'] == self::CACHEDATA_TYPE_CALLBACK) {
             $callback = $item['data'];
             if (is_callable($callback)) {
                 $retval[] = call_user_func($callback);
             } else {
                 // throw?
             }
         } else {
             if ($item['type'] == self::CACHEDATA_TYPE_RECURSION) {
                 if ($recurse) {
                     $retval[] = $c->get($item['data']);
                 }
             } else {
                 if ($item['type'] == self::CACHEDATA_TYPE_RECURSION_DATA) {
                     if ($recurse) {
                         $data = $c->getData($item['data']);
                         $retval[] = $data->stringify($c);
                     }
                 } else {
                     $retval[] = $item['data'];
                 }
             }
         }
     }
     return implode('', $retval);
 }
Ejemplo n.º 8
0
 /**
  * @param string|CacheKey $key
  * @return string
  */
 protected function cacheKey($key)
 {
     $stringKey = parent::cacheKey($key);
     // memcache doesn't like spaces in cache-keys
     return str_replace(' ', '_', $stringKey);
 }