當前位置: 首頁>>代碼示例>>PHP>>正文


PHP caching\Cache類代碼示例

本文整理匯總了PHP中yii\caching\Cache的典型用法代碼示例。如果您正苦於以下問題:PHP Cache類的具體用法?PHP Cache怎麽用?PHP Cache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Cache類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: releaseLock

 /**
  * @inheritdoc
  */
 protected function releaseLock($name)
 {
     if (!$this->cache instanceof Cache) {
         return false;
     }
     return $this->cache->delete($this->getCacheKey($name));
 }
開發者ID:intersvyaz,項目名稱:yii2-cache-mutex,代碼行數:10,代碼來源:Mutex.php

示例2: endGathering

 public function endGathering()
 {
     array_pop($this->cacheStack);
     $elements = $this->elements[$this->currentStackId];
     Yii::trace('End gathering:' . $this->currentStackId);
     $dependencies = array_pop($this->cacheStackDependencies);
     $this->cache->set($this->getCacheKey(), $elements, $this->cacheLifetime, $dependencies);
     unset($this->elements[$this->currentStackId]);
     $stack = $this->cacheStack;
     $this->currentStackId = end($stack);
     return $elements;
 }
開發者ID:tqsq2005,項目名稱:dotplant2,代碼行數:12,代碼來源:ViewElementsGathener.php

示例3: init

 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     if ($this->cache) {
         /** @var Cache $cache */
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheKey = __CLASS__;
         if (($this->_paramsInfo = $this->cache->get($cacheKey)) === false) {
             $this->_paramsInfo = $this->fetchParamsInfo();
             $this->cache->set($cacheKey, $this->_paramsInfo, $this->cacheDuration, $this->cacheDependency);
         }
     } else {
         $this->_paramsInfo = $this->fetchParamsInfo();
     }
 }
開發者ID:ezsky,項目名稱:yii2-platform-core,代碼行數:17,代碼來源:ParamsManager.php

示例4: getToken

 public function getToken($userId, $name, $portraitUri)
 {
     $cacheKey = 'token:' . serialize([strval($userId), strval($name), strval($portraitUri)]);
     if (!$this->cache instanceof Cache || false == ($results = $this->cache->get($cacheKey)) || !isset($results['token'])) {
         $response = $this->request('/user/getToken', ['userId' => $this->getUserAlias($userId), 'name' => $name, 'portraitUri' => $portraitUri]);
         $results = Json::decode($response, true);
         if (!isset($results['code']) || 200 != $results['code']) {
             throw new ResultException($response, '獲取token失敗');
         }
         if ($this->cache instanceof Cache) {
             $this->cache->set($cacheKey, $results, $this->tokenCacheDuration);
         }
     }
     return $results['token'];
 }
開發者ID:hughcube,項目名稱:apppush,代碼行數:15,代碼來源:RongCloud.php

示例5: init

 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!empty($this->cache)) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
開發者ID:cdcchen,項目名稱:yii2-wechat,代碼行數:10,代碼來源:QyClient.php

示例6: beforeAction

 public function beforeAction($action)
 {
     if (!$this->enabled) {
         return true;
     }
     $this->cache = Instance::ensure($this->cache, Cache::className());
     $this->cache->cachePath = Yii::getAlias($this->cachePath) . '/' . $action->getUniqueId();
     if (is_array($this->dependency)) {
         $this->dependency = Yii::createObject($this->dependency);
     }
     $properties = [];
     foreach (['cache', 'duration', 'dependency', 'variations'] as $name) {
         $properties[$name] = $this->{$name};
     }
     $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
     $response = Yii::$app->getResponse();
     ob_start();
     ob_implicit_flush(false);
     if ($this->view->beginCache($id, $properties)) {
         $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']);
         return true;
     } else {
         $data = $this->cache->get($this->calculateCacheKey());
         if (is_array($data)) {
             $this->restoreResponse($response, $data);
         }
         $response->content = ob_get_clean();
         return false;
     }
 }
開發者ID:VampireMe,項目名稱:admin-9939-com,代碼行數:30,代碼來源:PageCacheFilter.php

示例7: init

 /**
  * Initializes the DbMessageSource component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  * Configured [[cache]] component would also be initialized.
  * @throws InvalidConfigException if [[db]] is invalid or [[cache]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     if ($this->enableCaching) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
開發者ID:fonclub,項目名稱:i18n,代碼行數:14,代碼來源:DbMessageSource.php

示例8: init

 /**
  * Initialize the component
  */
 public function init()
 {
     parent::init();
     if ($this->cache !== null) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
     $this->model = new $this->modelClass();
 }
開發者ID:yii2song,項目名稱:yii2-settings,代碼行數:11,代碼來源:Settings.php

示例9: 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

示例10: actionFlushCache

 public function actionFlushCache($component = 'cache')
 {
     /** @var Cache $cache */
     $cache = Instance::ensure($component, Cache::className());
     $cache->flush();
     Yii::$app->session->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Cache flushed.'));
     return $this->redirect(['index']);
 }
開發者ID:ezsky,項目名稱:yii2-platform-core,代碼行數:8,代碼來源:DefaultController.php

示例11: __construct

 /**
  * Singleton construct.
  */
 protected function __construct()
 {
     try {
         $this->cache = Instance::ensure($this->cache, DefaultCache::className());
     } catch (Exception $e) {
         $this->cache = new DummyCache();
     }
 }
開發者ID:Avenger1,項目名稱:yii2-podium,代碼行數:11,代碼來源:Cache.php

示例12: run

 public function run()
 {
     if ($this->cache) {
         /** @var Cache $cache */
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheKey = [__CLASS__, $this->items];
         if (($this->items = $this->cache->get($cacheKey)) === false) {
             $this->items = ModuleEvent::trigger(self::EVENT_FETCH_ITEMS, new MenuItemsEvent(['items' => $this->items]), 'items');
             $this->cache->set($cacheKey, $this->items, $this->cacheDuration, $this->cacheDependency);
         }
     } else {
         $this->items = ModuleEvent::trigger(self::EVENT_FETCH_ITEMS, new MenuItemsEvent(['items' => $this->items]), 'items');
     }
     $this->items += $this->customItems;
     parent::run();
     // TODO: Change the autogenerated stub
 }
開發者ID:oakcms,項目名稱:oakcms,代碼行數:17,代碼來源:Menu.php

示例13: init

 public function init()
 {
     if ($this->cache) {
         /** @var Cache $cache */
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheKey = __CLASS__;
         if ((list($paths, $routes, $links) = $this->cache->get($cacheKey)) === false) {
             $this->createMap();
             $this->cache->set($cacheKey, [$this->_paths, $this->_routes, $this->_links], $this->cacheDuration, $this->cacheDependency);
         } else {
             $this->_paths = $paths;
             $this->_routes = $routes;
             $this->_links = $links;
         }
     } else {
         $this->createMap();
     }
 }
開發者ID:ezsky,項目名稱:yii2-platform-core,代碼行數:18,代碼來源:MenuMap.php

示例14: init

 /**
  * 初始化組件
  */
 public function init()
 {
     parent::init();
     if ($this->cache !== null) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     } else {
         throw new InvalidConfigException("Cache must be turned on");
     }
     self::$wechat = $this;
 }
開發者ID:Brother-Simon,項目名稱:yii2-wechat-component,代碼行數:13,代碼來源:Wechat.php

示例15: 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


注:本文中的yii\caching\Cache類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。