本文整理汇总了PHP中yii\caching\Cache::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::init方法的具体用法?PHP Cache::init怎么用?PHP Cache::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\caching\Cache
的用法示例。
在下文中一共展示了Cache::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* 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);
}
}
}
}
}
示例2: init
/**
* 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);
}
}
示例3: init
/**
* 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.");
}
}
示例4: init
/**
* 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.");
}
}
示例5: init
/**
* 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());
}
}
示例6: init
/**
* 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.");
}
}
示例7: init
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) . "___";
}
}
示例8: init
/**
* 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.");
}
}
示例9: init
/**
* 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());
}
示例10: init
/**
* Initializes this application component.
* It creates the memcache instance and adds memcache servers.
*/
public function init()
{
parent::init();
$this->addServers($this->getMemcache(), $this->getServers());
}
示例11: init
/**
* 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);
}
示例12: init
/**
* Initializes this application component.
* @throws InvalidConfigException if redis extension is not loaded
*/
public function init()
{
parent::init();
$this->makeReadConnection();
}
示例13: init
/**
* Initializes this application component.
* It creates the memcache instance and adds memcache servers.
*/
public function init()
{
parent::init();
$this->getMemcached();
}
示例14: init
/**
* 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();
}
示例15: init
/**
* Initializes the S3 client.
*/
public function init()
{
parent::init();
$this->_client = S3Client::factory($this->config);
}