예제 #1
0
파일: File.php 프로젝트: vzina/yaf-api
 /**
  * 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'], '\\/');
 }
예제 #2
0
파일: Xcache.php 프로젝트: vzina/yaf-api
 /**
  * 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);
 }
예제 #3
0
파일: Yac.php 프로젝트: vzina/yaf-api
 /**
  * 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);
 }
예제 #4
0
파일: Memcache.php 프로젝트: vzina/yaf-api
 /**
  * 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);
     }
 }
예제 #5
0
파일: Memcached.php 프로젝트: vzina/yaf-api
 /**
  * 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']);
 }
예제 #6
0
파일: Redis.php 프로젝트: vzina/yaf-api
 /**
  * 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]);
         }
     }
 }
예제 #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);
 }
예제 #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);
 }