コード例 #1
0
ファイル: MemCache.php プロジェクト: yuexiaoyun/lulucms
 /**
  * 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
0
ファイル: FileCache.php プロジェクト: yuexiaoyun/lulucms
 /**
  * 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
0
ファイル: ApcCache.php プロジェクト: Kest007/yii2
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
ファイル: Cache.php プロジェクト: nguyentuansieu/BioMedia
 /**
  * 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
0
ファイル: Cache.php プロジェクト: myweishanli/yii2-ssdb
 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
0
ファイル: Cache.php プロジェクト: nserban/yii2-aerospike
 /**
  * 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
0
ファイル: DbCache.php プロジェクト: yuexiaoyun/lulucms
 /**
  * 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
0
ファイル: MemCache.php プロジェクト: noorafree/makmakan
 /**
  * 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
0
ファイル: Cache.php プロジェクト: fgh151/yii2-tarantool
 /**
  * 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
0
 /**
  * Initializes this application component.
  * @throws InvalidConfigException if redis extension is not loaded
  */
 public function init()
 {
     parent::init();
     $this->makeReadConnection();
 }
コード例 #13
0
 /**
  * Initializes this application component.
  * It creates the memcache instance and adds memcache servers.
  */
 public function init()
 {
     parent::init();
     $this->getMemcached();
 }
コード例 #14
0
 /**
  * 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
0
ファイル: Cache.php プロジェクト: urbanindo/yii2-s3cache
 /**
  * Initializes the S3 client.
  */
 public function init()
 {
     parent::init();
     $this->_client = S3Client::factory($this->config);
 }