/** * Initialize the Redis instance and set all relevant options. * * @throws \Titon\Io\Exception\MissingExtensionException * @throws \Titon\Cache\Exception\InvalidServerException * @throws \Titon\Cache\Exception\AuthenticateFailureException */ public function initialize() { parent::initialize(); if (!extension_loaded('redis')) { throw new MissingExtensionException('Redis extension is not loaded'); } $config = $this->allConfig(); if (!$config['server']) { throw new InvalidServerException(sprintf('No server has been defined for %s', $this->inform('className'))); } $this->connection = new Redis(); if (extension_loaded('igbinary')) { $this->connection->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); } list($host, $port, $timeout) = $this->parseServer($config['server'], static::PORT, 0); if ($config['persistent']) { $this->connection->pconnect($host, $port, $timeout); } else { $this->connection->connect($host, $port, $timeout); } if ($config['password']) { if (!$this->connection->auth($config['password'])) { throw new AuthenticateFailureException('Could not authenticate with Redis'); } } }
/** * Validate that Wincache is installed. * * @throws \Titon\Io\Exception\MissingExtensionException */ public function initialize() { parent::initialize(); if (!extension_loaded('wincache')) { throw new MissingExtensionException('Wincache extension is not loaded'); } }
/** * Initialize the Memcached instance and set all relevant options. * * @throws \Titon\Io\Exception\MissingExtensionException * @throws \Titon\Cache\Exception\InvalidServerException */ public function initialize() { parent::initialize(); if (!extension_loaded('memcached')) { throw new MissingExtensionException('Memcache extension is not loaded'); } $config = $this->allConfig(); if (!$config['server']) { throw new InvalidServerException(sprintf('No server has been defined for %s', $this->inform('className'))); } if ($config['persistent'] && !$config['id']) { $config['id'] = 'titon'; } $this->connection = new Memcached($config['id']); $serverList = $this->connection->getServerList(); // Only add servers if none exist if (empty($serverList)) { $this->connection->setOption(Memcached::OPT_COMPRESSION, (bool) $config['compress']); $this->connection->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true); $this->connection->setOption(Memcached::OPT_BUFFER_WRITES, (bool) $config['buffer']); if ($config['persistent']) { $this->connection->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT); } if (extension_loaded('igbinary')) { $this->connection->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY); } if (is_array($config['server'])) { $this->connection->addServers(array_map([$this, 'parseServer'], $config['server'])); } else { list($host, $port, $weight) = $this->parseServer($config['server'], static::PORT, static::WEIGHT); $this->connection->addServer($host, $port, $weight); } } }
/** * Validate that APC is installed. * * @throws \Titon\Io\Exception\MissingExtensionException */ public function initialize() { parent::initialize(); if (!extension_loaded('apc')) { throw new MissingExtensionException('APC extension is not loaded'); } }
/** * Always use serialization with file system caching. * * @uses Titon\Utility\Path * * @throws \Titon\Io\Exception\MissingFileException */ public function initialize() { parent::initialize(); $path = $this->getConfig('directory'); if (!$path) { throw new MissingFileException('Temporary storage directory not defined'); } $this->_folder = new Folder($path, true); }
/** * Validate that APC is installed. * * @throws \Titon\Io\Exception\MissingExtensionException */ public function initialize() { parent::initialize(); if (!extension_loaded('xcache')) { throw new MissingExtensionException('Xcache extension is not loaded'); } if ($this->getConfig('compress')) { ini_set('xcache.optimizer', true); } ini_set('xcache.admin.user', $this->getConfig('username')); ini_set('xcache.admin.pass', $this->getConfig('password')); }