当前位置: 首页>>代码示例>>PHP>>正文


PHP Cache::init方法代码示例

本文整理汇总了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);
                 }
             }
         }
     }
 }
开发者ID:yuexiaoyun,项目名称:lulucms,代码行数:35,代码来源:MemCache.php

示例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);
     }
 }
开发者ID:yuexiaoyun,项目名称:lulucms,代码行数:11,代码来源:FileCache.php

示例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.");
     }
 }
开发者ID:Kest007,项目名称:yii2,代码行数:12,代码来源:ApcCache.php

示例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.");
     }
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:15,代码来源:DbCache.php

示例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());
     }
 }
开发者ID:husccexo,项目名称:yii2-handlersocket,代码行数:19,代码来源:HSCache.php

示例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.");
     }
 }
开发者ID:nguyentuansieu,项目名称:BioMedia,代码行数:20,代码来源:Cache.php

示例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) . "___";
     }
 }
开发者ID:myweishanli,项目名称:yii2-ssdb,代码行数:18,代码来源:Cache.php

示例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.");
     }
 }
开发者ID:nserban,项目名称:yii2-aerospike,代码行数:26,代码来源:Cache.php

示例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());
 }
开发者ID:yuexiaoyun,项目名称:lulucms,代码行数:10,代码来源:DbCache.php

示例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());
 }
开发者ID:noorafree,项目名称:makmakan,代码行数:9,代码来源:MemCache.php

示例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);
 }
开发者ID:fgh151,项目名称:yii2-tarantool,代码行数:11,代码来源:Cache.php

示例12: init

 /**
  * Initializes this application component.
  * @throws InvalidConfigException if redis extension is not loaded
  */
 public function init()
 {
     parent::init();
     $this->makeReadConnection();
 }
开发者ID:NetClearly,项目名称:yii2-extensions,代码行数:9,代码来源:RedisCache.php

示例13: init

 /**
  * Initializes this application component.
  * It creates the memcache instance and adds memcache servers.
  */
 public function init()
 {
     parent::init();
     $this->getMemcached();
 }
开发者ID:hustnaive,项目名称:yii-advanced-modular-vendor,代码行数:9,代码来源:AliCache.php

示例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();
 }
开发者ID:robinclark007,项目名称:sae-yii2-memcache,代码行数:10,代码来源:SaeMemCache.php

示例15: init

 /**
  * Initializes the S3 client.
  */
 public function init()
 {
     parent::init();
     $this->_client = S3Client::factory($this->config);
 }
开发者ID:urbanindo,项目名称:yii2-s3cache,代码行数:8,代码来源:Cache.php


注:本文中的yii\caching\Cache::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。