/** * Constructor * * @access public * * @param array $config config array * * @result void * @throws Exception */ public function __construct(array $config = []) { parent::__construct($config); if (empty($config['type']) || !$this->check()) { throw new Exception('Memcache(d) not installed or not select type'); } switch (strtolower($config['type'])) { case 'memcached': $this->driver = new \Memcached(); break; case 'memcache': $this->driver = new \Memcache(); break; default: throw new Exception('Selected type not valid in the driver'); } if (!empty($config['servers'])) { $this->driver->addServers($config['servers']); } elseif ($config['server']) { $conf = $config['server']; $server = ['hostname' => !empty($conf['hostname']) ? $conf['hostname'] : '127.0.0.1', 'port' => !empty($conf['port']) ? $conf['port'] : 11211, 'weight' => !empty($conf['weight']) ? $conf['weight'] : 1]; if (get_class($this->driver) === 'Memcached') { $this->driver->addServer($server['hostname'], $server['port'], $server['weight']); } else { $this->driver->addServer($server['hostname'], $server['port'], true, $server['weight']); } } else { throw new Exception('Server(s) not configured'); } }
/** * Constructor * * @access public * * @param array $config array config * * @result void * @throws Exception */ public function __construct(array $config = []) { parent::__construct($config); if (!$this->check()) { throw new Exception('Extension WinCache not installed'); } }
/** * Constructor * * @access pubic * * @param array $config config array * * @result void */ public function __construct(array $config = []) { parent::__construct($config); $path = !empty($config['path']) ? $config['path'] : sys_get_temp_dir() . '/cache'; if (!is_dir($path)) { mkdir($path, 0600); } $this->driver = $path; }
/** * Constructor * * @access public * * @param array $config config array * * @result void */ public function __construct(array $config = []) { parent::__construct($config); $this->table = 'cache'; if (!empty($config['table'])) { $this->table = $config['table']; unset($config['table']); } $cls = $config['class']; $this->driver = new $cls($config); $this->driver->createTable($this->table, ['`name` VARCHAR(127) NOT NULL', '`value` TEXT NULL', '`duration` INT(11) NOT NULL', '`date_create` INT(11) NOT NULL', 'UNIQUE(`name`)'], ''); }
/** * Constructor * * @access public * * @param array $config config array * * @result void * @throws Exception */ public function __construct(array $config = []) { parent::__construct($config); if (!$this->check()) { throw new Exception('Redis not installed on system'); } $this->driver = new \Redis(); try { if (!empty($config['socket_type']) && $config['socket_type'] === 'unix') { $result = $this->driver->connect($config['socket']); } else { $result = $this->driver->connect($config['host'], $config['port'], $config['duration']); } } catch (\RedisException $e) { throw new Exception((string) $e); } if (!$result) { throw new Exception('Redis configuration failed'); } }