當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。