コード例 #1
0
ファイル: memcached.php プロジェクト: wushian/MDD
 public function __construct($identifier, $config)
 {
     parent::__construct($identifier, $config);
     $this->config = isset($config['memcached']) ? $config['memcached'] : array();
     // make sure we have a memcache id
     $this->config['cache_id'] = $this->_validate_config('cache_id', isset($this->config['cache_id']) ? $this->config['cache_id'] : 'fuel');
     // check for an expiration override
     $this->expiration = $this->_validate_config('expiration', isset($this->config['expiration']) ? $this->config['expiration'] : $this->expiration);
     if ($this->memcached === false) {
         // make sure we have memcached servers configured
         $this->config['servers'] = $this->_validate_config('servers', $this->config['servers']);
         // do we have the PHP memcached extension available
         if (!class_exists('Memcached')) {
             throw new \FuelException('Memcached cache are configured, but your PHP installation doesn\'t have the Memcached extension loaded.');
         }
         // instantiate the memcached object
         $this->memcached = new \Memcached();
         // add the configured servers
         $this->memcached->addServers($this->config['servers']);
         // check if we can connect to the server(s)
         if ($this->memcached->getVersion() === false) {
             throw new \FuelException('Memcached cache are configured, but there is no connection possible. Check your configuration.');
         }
     }
 }
コード例 #2
0
ファイル: redis.php プロジェクト: nasumi/fuel
	public function __construct($identifier, $config)
	{
		$this->config = isset($config['redis']) ? $config['redis'] : array();

		// make sure we have a redis id
		$this->config['cache_id'] = $this->_validate_config('cache_id', isset($this->config['cache_id']) ? $this->config['cache_id'] : 'fuel');

		// check for an expiration override
		$this->expiration = $this->_validate_config('expiration', isset($this->config['expiration']) ? $this->config['expiration'] : $this->expiration);

		// make sure we have a redis database configured
		$this->config['database'] = $this->_validate_config('database', isset($this->config['database']) ? $this->config['database'] : 'default');

		if ($this->redis === false)
		{
			// get the redis database instance
			try
			{
				$this->redis = \Redis::instance($this->config['database']);
			}
			catch (Exception $e)
			{
				throw new \Cache_Exception('Can not connect to the Redis engine. The error message says "'.$e->getMessage().'".');
			}

			// get the redis version
			preg_match('/redis_version:(.*?)\n/', $this->redis->info(), $info);
			if (version_compare(trim($info[1]), '1.2') < 0)
			{
				throw new \Cache_Exception('Version 1.2 or higher of the Redis NoSQL engine is required to use the redis cache driver.');
			}
		}

		parent::__construct($identifier, $config);
	}
コード例 #3
0
 public function __construct($identifier, $config)
 {
     parent::__construct($identifier, $config);
     $this->config = isset($config['memcached']) ? $config['memcached'] : array();
     // make sure we have a memcache id
     $this->config['cache_id'] = $this->_validate_config('cache_id', isset($this->config['cache_id']) ? $this->config['cache_id'] : 'fuel');
     // check for an expiration override
     $this->expiration = $this->_validate_config('expiration', isset($this->config['expiration']) ? $this->config['expiration'] : $this->expiration);
     if (static::$memcached === false) {
         // make sure we have memcached servers configured
         $this->config['servers'] = $this->_validate_config('servers', $this->config['servers']);
         // do we have the PHP memcached extension available
         if (!class_exists('Memcached')) {
             throw new \FuelException('Memcached cache are configured, but your PHP installation doesn\'t have the Memcached extension loaded.');
         }
         // instantiate the memcached object
         static::$memcached = new \Memcached();
         // add the configured servers
         static::$memcached->addServers($this->config['servers']);
         // check if we can connect to all the server(s)
         $added = static::$memcached->getStats();
         foreach ($this->config['servers'] as $server) {
             $server = $server['host'] . ':' . $server['port'];
             if (!isset($added[$server]) or $added[$server]['pid'] == -1) {
                 throw new \FuelException('Memcached sessions are configured, but there is no connection possible. Check your configuration.');
             }
         }
     }
 }
コード例 #4
0
ファイル: file.php プロジェクト: netspencer/fuel
 public function __construct($identifier, $config)
 {
     $this->config = isset($config['file']) ? $config['file'] : array();
     // check for an expiration override
     $this->expiration = $this->_validate_config('expiration', isset($this->config['expiration']) ? $this->config['expiration'] : $this->expiration);
     // determine the file cache path
     static::$path = !empty($this->config['path']) ? $this->config['path'] : APPPATH . 'cache' . DS;
     if (!is_dir(static::$path) || !is_writable(static::$path)) {
         throw new \Cache_Exception('Cache directory does not exist or is not writable.');
     }
     parent::__construct($identifier, $config);
 }
コード例 #5
0
ファイル: xcache.php プロジェクト: takawasitobi/pembit
 public function __construct($identifier, $config)
 {
     parent::__construct($identifier, $config);
     $this->config = isset($config['xcache']) ? $config['xcache'] : array();
     // make sure we have an id
     $this->config['cache_id'] = $this->_validate_config('cache_id', isset($this->config['cache_id']) ? $this->config['cache_id'] : 'fuel');
     // check for an expiration override
     $this->expiration = $this->_validate_config('expiration', isset($this->config['expiration']) ? $this->config['expiration'] : $this->expiration);
     // do we have the PHP XCache extension available
     if (!function_exists('xcache_set')) {
         throw new \FuelException('Your PHP installation doesn\'t have XCache loaded.');
     }
 }