/** * Initializes this application component. * It creates the memcache instance and adds memcache servers. */ public function init() { parent::init(); $servers = $this->getServers(); $cache = $this->getMemCache(); if (empty($servers)) { $cache->addServer('127.0.0.1', 11211); } else { if (!$this->useMemcached) { // different version of memcache may have different number of parameters for the addServer method. $class = new \ReflectionClass($cache); $paramCount = $class->getMethod('addServer')->getNumberOfParameters(); } foreach ($servers as $server) { if ($server->host === null) { throw new InvalidConfigException("The 'host' property must be specified for every memcache server."); } if ($this->useMemcached) { $cache->addServer($server->host, $server->port, $server->weight); } else { // $timeout is used for memcache versions that do not have timeoutms parameter $timeout = (int) ($server->timeout / 1000) + ($server->timeout % 1000 > 0 ? 1 : 0); if ($paramCount === 9) { $cache->addServer($server->host, $server->port, $server->persistent, $server->weight, $timeout, $server->retryInterval, $server->status, $server->failureCallback, $server->timeout); } else { $cache->addServer($server->host, $server->port, $server->persistent, $server->weight, $timeout, $server->retryInterval, $server->status, $server->failureCallback); } } } } }
/** * Initializes this component by ensuring the existence of the cache path. */ public function init() { parent::init(); $this->cachePath = Yii::getAlias($this->cachePath); if (!is_dir($this->cachePath)) { FileHelper::createDirectory($this->cachePath, $this->dirMode, true); } }
/** * Initializes this application component. * It checks if extension required is loaded. */ public function init() { parent::init(); $extension = $this->useApcu ? 'apcu' : 'apc'; if (!extension_loaded($extension)) { throw new InvalidConfigException("ApcCache requires PHP {$extension} extension to be loaded."); } }
/** * Initializes the DbCache component. * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. * @throws InvalidConfigException if [[db]] is invalid. */ public function init() { parent::init(); if (is_string($this->db)) { $this->db = Yii::$app->getComponent($this->db); } if (!$this->db instanceof Connection) { throw new InvalidConfigException("DbCache::db must be either a DB connection instance or the application component ID of a DB connection."); } }
/** * Initializes the HSCache component. * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. * @throws InvalidConfigException if [[db]] is invalid. */ public function init() { parent::init(); switch ($this->mode) { case 'multiType': $this->hs = new \HSLib\CacheMultiType($this->host . ':' . $this->portRead, $this->secret, $this->host . ':' . $this->portWrite, $this->secret, $this->db, $this->table, $this->debug); break; case 'multiTable': $this->hs = new \HSLib\CacheMultiTable($this->host . ':' . $this->portRead, $this->secret, $this->host . ':' . $this->portWrite, $this->secret, $this->db, $this->debug); break; default: throw new InvalidConfigException('Wrong mode in ' . HSCache::className()); } }
/** * Initializes the redis Cache component. * This method will initialize the [[redis]] property to make sure it refers to a valid redis connection. * @throws InvalidConfigException if [[redis]] is invalid. */ public function init() { parent::init(); if (is_string($this->redis)) { $this->redis = Yii::$app->get($this->redis); } elseif (is_array($this->redis)) { if (!isset($this->redis['class'])) { $this->redis['class'] = Connection::className(); } $this->redis = Yii::createObject($this->redis); } if (!$this->redis instanceof Connection) { throw new InvalidConfigException("Cache::redis must be either a Redis connection instance or the application component ID of a Redis connection."); } }
public function init() { parent::init(); if (is_string($this->ssdb)) { $this->ssdb = \Yii::$app->get($this->ssdb); } elseif (is_array($this->ssdb)) { if (!isset($this->ssdb['class'])) { $this->ssdb['class'] = Connection::className(); } $this->ssdb = \Yii::createObject($this->ssdb); } if (!$this->ssdb instanceof Connection) { throw new InvalidConfigException("Cache::ssdb must be either a Ssdb Connection instance or the application component ID of a ssdb Connection."); } if ($this->cache_keys_hash === "") { $this->{$cache_keys_hash} = substr(md5(Yii::$app->id), 0, 5) . "___"; } }
/** * Initializes the aerospike Cache component. * This method will initialize the [[aerospike]] property to make sure it refers to a valid aerospike connection. * @throws InvalidConfigException if [[aerospike]] is invalid. */ public function init() { parent::init(); // Set serializer for aerospike $this->serializer = [function ($value) { return $value[0]; }, function ($value) { return [$value, null]; }]; if (is_string($this->aerospike)) { $this->aerospike = Yii::$app->get($this->aerospike); } elseif (is_array($this->aerospike)) { if (!isset($this->aerospike['class'])) { $this->aerospike['class'] = Connection::className(); } $this->aerospike = Yii::createObject($this->aerospike); } if (!$this->aerospike instanceof Connection) { throw new InvalidConfigException("Cache::aerospike must be either a Aerospike connection instance or the application component ID of a Aerospike connection."); } }
/** * Initializes the DbCache component. * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. * @throws InvalidConfigException if [[db]] is invalid. */ public function init() { parent::init(); $this->db = Instance::ensure($this->db, Connection::className()); }
/** * Initializes this application component. * It creates the memcache instance and adds memcache servers. */ public function init() { parent::init(); $this->addServers($this->getMemcache(), $this->getServers()); }
/** * Initializes the Cache component. * This method will initialize the [[db]] property to make sure it refers to a valid MongoDB connection. * @throws InvalidConfigException if [[db]] is invalid. */ public function init() { parent::init(); $this->Client = new Client(new SocketConnection($this->Server, $this->Port), new PurePacker()); $this->Space = $this->Client->getSpace($this->SpaceName); }
/** * Initializes this application component. * @throws InvalidConfigException if redis extension is not loaded */ public function init() { parent::init(); $this->makeReadConnection(); }
/** * Initializes this application component. * It creates the memcache instance and adds memcache servers. */ public function init() { parent::init(); $this->getMemcached(); }
/** * Initializes this application component. * It creates the memcache instance and adds memcache servers. */ public function init() { parent::init(); $this->_cache = new \Memcache(); $this->_cache->connect(); }
/** * Initializes the S3 client. */ public function init() { parent::init(); $this->_client = S3Client::factory($this->config); }