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


PHP Cache::get方法代码示例

本文整理汇总了PHP中yii\caching\Cache::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::get方法的具体用法?PHP Cache::get怎么用?PHP Cache::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\caching\Cache的用法示例。


在下文中一共展示了Cache::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * @inheritdoc
  */
 public function load()
 {
     $contents = $this->yiiCache->get($this->key);
     if ($contents !== false) {
         $this->setFromStorage($contents);
     }
 }
开发者ID:hassiumsoft,项目名称:hasscms-app-vendor,代码行数:10,代码来源:YiiCache.php

示例2: load

 protected function load()
 {
     $this->items = $this->cache->get('settings');
     if (!$this->items) {
         $this->items = [];
         $rows = (new Query())->from($this->tableName)->all($this->db);
         foreach ($rows as $row) {
             $this->items[$row['category']][$row['key']] = @unserialize($row['value']);
         }
         $this->cache->set('settings', $this->items, $this->cacheTime);
     }
 }
开发者ID:olessavluk,项目名称:yii2-settings,代码行数:12,代码来源:SettingsComponent.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: acquireLock

 /**
  * @inheritdoc
  */
 protected function acquireLock($name, $timeout = 0)
 {
     if (!$this->cache instanceof Cache) {
         return false;
     }
     $waitTime = 0;
     while ($this->cache->get($this->getCacheKey($name)) !== false) {
         $waitTime++;
         if ($waitTime > $timeout) {
             return false;
         }
         sleep(1);
     }
     return $this->cache->set($this->getCacheKey($name), true);
 }
开发者ID:intersvyaz,项目名称:yii2-cache-mutex,代码行数:18,代码来源:Mutex.php

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

示例6: getAllAssignments

 /**
  * @return array
  * @throws \yii\base\InvalidConfigException
  */
 protected function getAllAssignments()
 {
     $result = [];
     $useCache = $this->useCache === true;
     if ($useCache && $this->cache->exists('assignments-0')) {
         echo '    > Assignments cache exists.' . PHP_EOL;
         $answer = $this->prompt('      > Use cache? [yes/no]');
         if (strpos($answer, 'y') === 0) {
             $this->cacheIterator(function ($key) use(&$result) {
                 $result = ArrayHelper::merge($result, $this->cache->get($key));
             });
             return $result;
         }
     }
     /** @var \yii\db\ActiveQuery $UsersQuery */
     $UsersQuery = call_user_func([$this->user->identityClass, 'find']);
     /** @var \yii\web\IdentityInterface[] $Users */
     foreach ($UsersQuery->batch($this->batchSize, $this->db) as $k => $Users) {
         $chunk = [];
         foreach ($Users as $User) {
             $pk = $User->getId();
             $assignments = array_keys($this->authManager->getAssignments($pk));
             $chunk[$pk] = $assignments;
             $result[$pk] = $assignments;
         }
         if ($useCache) {
             $this->cache->set(sprintf('assignments-%d', $k), $chunk);
         }
     }
     return $result;
 }
开发者ID:rmrevin,项目名称:yii2-rbac-command,代码行数:35,代码来源:Command.php

示例7: getFromCache

 private function getFromCache($part)
 {
     if ($this->enableCaching) {
         return $this->cache->get($this->buildKey($part));
     }
     return false;
 }
开发者ID:hscstudio,项目名称:yii2-heart,代码行数:7,代码来源:DbManager.php

示例8: getFromCache

 /**
  * @param int|string $userId
  * @param string $key
  * @return bool|mixed
  */
 protected function getFromCache($userId, $key)
 {
     if ($this->cacheIsActive()) {
         return $this->cache->get($this->buildCacheKey($userId, $key));
     } else {
         return false;
     }
 }
开发者ID:cdcchen,项目名称:yii-plus,代码行数:13,代码来源:UserConfig.php

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

示例10: getHasChanged

 /**
  * Performs the actual dependency checking.
  * @param Cache $cache the cache component that is currently evaluating this dependency
  * @return boolean whether the dependency is changed or not.
  * @throws InvalidConfigException if [[group]] is not set.
  */
 public function getHasChanged($cache)
 {
     if ($this->group === null) {
         throw new InvalidConfigException('GroupDependency::group must be set');
     }
     $version = $cache->get([__CLASS__, $this->group]);
     return $version === false || $version !== $this->data;
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:14,代码来源:GroupDependency.php

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

示例12: init

 public function init()
 {
     if (!$this->language) {
         throw new InvalidConfigException(get_called_class() . '::language must be set.');
     }
     if ($this->cache) {
         /** @var Cache $cache */
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheKey = [__CLASS__, $this->language];
         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:gromver,项目名称:yii2-platform-basic,代码行数:21,代码来源:MenuMap.php

示例13: get

 /**
  * 通过API查询IP信息
  * @param null $ip
  * @return IpData|mixed
  */
 public function get($ip = null)
 {
     $ip = $ip === null ? Yii::$app->request->userIP : $ip;
     $ipData = new IpData();
     $cacheKey = $this->getCacheKey($ip);
     if ($this->cache !== null && ($json = $this->cache->get($cacheKey))) {
         $ipData->setAttributes(json_decode($json, true), false);
         return $ipData;
     }
     $context = stream_context_create(['http' => ['timeout' => 1]]);
     $url = $this->_url . $ip;
     try {
         $result = json_decode(file_get_contents($url, 0, $context), true);
     } catch (Exception $e) {
         $result = null;
     }
     if ($result && $result['code'] == 0) {
         $ipData->setAttributes($result['data'], false);
         $this->cache !== null && $this->cache->set($cacheKey, json_encode($ipData), $this->cacheDuration);
     }
     return $ipData;
 }
开发者ID:highestgoodlikewater,项目名称:yii2-taobao-ip,代码行数:27,代码来源:IpComponent.php

示例14: getData

 /**
  * Get data
  * @return array
  */
 public function getData()
 {
     if ($this->_data === null) {
         if ($this->_cache !== null) {
             $cache = $this->_cache->get($this->cacheKey);
             if ($cache === false) {
                 $this->_data = $this->_getDataFromDb();
                 $this->_setCache();
             } else {
                 $this->_data = $cache;
             }
         } else {
             $this->_data = $this->_getDataFromDb();
         }
     }
     return $this->_data;
 }
开发者ID:rocketyang,项目名称:hasscms-app,代码行数:21,代码来源:Config.php

示例15: getAppRoutes

 /**
  * Get list of application routes
  *
  * @param string|null $module
  *
  * @return array
  */
 public function getAppRoutes($module = null)
 {
     if ($module === null) {
         $module = Yii::$app;
     } elseif (is_string($module)) {
         $module = Yii::$app->getModule($module);
     }
     $key = [__METHOD__, $module->getUniqueId()];
     $result = $this->cache !== null ? $this->cache->get($key) : false;
     if ($result === false) {
         $result = [];
         $this->getRouteRecursive($module, $result);
         if ($this->cache !== null) {
             $this->cache->set($key, $result, $this->cacheDuration, new TagDependency(['tags' => self::CACHE_TAG]));
         }
     }
     return $result;
 }
开发者ID:yii2mod,项目名称:yii2-rbac,代码行数:25,代码来源:RouteModel.php


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