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


PHP Cache::add方法代码示例

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


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

示例1: _fetchDataset

 private function _fetchDataset($filter)
 {
     return Cache::get($this->key, function () use($filter) {
         Cache::add($this->key, $data = $this->_getDataPartialRecursive($filter), 60);
         return $data;
     });
 }
开发者ID:skizu,项目名称:freshdeskreporting,代码行数:7,代码来源:DataController.php

示例2: getSiteMap

 /**
  * Return the content of the Site Map
  */
 public function getSiteMap()
 {
     if (Cache::has('site-map')) {
         return Cache::get('site-map');
     }
     $siteMap = $this->buildSiteMap();
     Cache::add('site-map', $siteMap, 120);
     return $siteMap;
 }
开发者ID:canwonson,项目名称:myWeb,代码行数:12,代码来源:SiteMap.php

示例3: getRSS

 /**
  * Return the content of the RSS feed
  */
 public function getRSS()
 {
     if (Cache::has('rss-feed')) {
         return Cache::get('rss-feed');
     }
     $rss = $this->buildRssData();
     Cache::add('rss-feed', $rss, 120);
     return $rss;
 }
开发者ID:railto,项目名称:MySite-Laravel,代码行数:12,代码来源:RssFeed.php

示例4: index

 public function index() : string
 {
     if (Cache::has('rss-feed')) {
         return Cache::get('rss-feed');
     }
     $rss = $this->assembleFeed();
     Cache::add('rss-feed', $rss, 120);
     return $rss;
 }
开发者ID:genealabs,项目名称:laravel-weblog,代码行数:9,代码来源:Rss.php

示例5: incrementLoginAttempts

 protected function incrementLoginAttempts(Request $request)
 {
     $key = $this->getLoginAttemptsKey($request);
     if (!Cache::has($key)) {
         Cache::add($key, 1, static::LOGIN_LOCKOUT_MINUTES);
         return 1;
     }
     return (int) Cache::increment($key);
 }
开发者ID:SerdarSanri,项目名称:laravel-auth-pack,代码行数:9,代码来源:ThrottlesLoginsTrait.php

示例6: getHot

 public static function getHot()
 {
     if (!Cache::has(GlobalVar::$HOT_CACHE)) {
         $bili_util = new BiliUtil();
         $hot_list = $bili_util->getHot();
         Cache::add(GlobalVar::$HOT_CACHE, $hot_list, 60 * 5);
     } else {
         $hot_list = Cache::get(GlobalVar::$HOT_CACHE);
     }
     return $hot_list;
 }
开发者ID:bajian,项目名称:BiliPusher,代码行数:11,代码来源:CacheSetter.php

示例7: setInCache

 private function setInCache($name, $data, $cache = null)
 {
     if ($this->config['enable_cache']) {
         $lifeTime = is_null($cache) ? $this->config['cache_live_time'] : $cache;
         $created_at = Carbon::now();
         $data['cache']['enabled'] = true;
         $data['cache']['created_at'] = $created_at->timestamp;
         $data['cache']['end_at'] = $created_at->addMinutes($lifeTime)->timestamp;
         Cache::add($name, $data, $lifeTime);
     }
 }
开发者ID:esalazarv,项目名称:resource,代码行数:11,代码来源:ResourceTrait.php

示例8: getHotArticleList

 /**
  * 获取热门文章列表
  * @param $n        取出数量
  * @return array
  */
 public static function getHotArticleList($n)
 {
     if (empty($articles = Cache::get(self::REIDS_HOT_ARTICLE_CACHE))) {
         $articles = [];
         $ids = ArticleStatus::limit($n)->orderBy('view_number', 'desc')->get();
         foreach ($ids as $v) {
             if ($article = self::getArticleModelByArticleId($v->art_id)) {
                 array_push($articles, $article);
             }
         }
         Cache::add(self::REIDS_HOT_ARTICLE_CACHE, $articles, config('site')['redis_cache_time']);
     }
     return $articles;
 }
开发者ID:xinzou,项目名称:blog,代码行数:19,代码来源:Article.php

示例9: incrementLoginAttempts

 /**
  * Increment the login attempts for the user.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return int
  */
 protected function incrementLoginAttempts(Request $request)
 {
     Cache::add($key = $this->getLoginAttemptsKey($request), 1, 1);
     return (int) Cache::increment($key);
 }
开发者ID:MachiavelliQ,项目名称:www,代码行数:11,代码来源:ThrottlesLogins.php

示例10: createCache

 public function createCache()
 {
     $this->hasError();
     Cache::add($this->qdn->slug, user()->employee->name, 5);
     return $this;
 }
开发者ID:rob1121,项目名称:qdn,代码行数:6,代码来源:ViewPage.php

示例11: getRateSeries

 /**
  * Get a RateSeries (not supported by Yahoo)
  *
  * @param type $from
  * @param type $to
  * @param type $dateStart
  * @param type $dateEnd
  *
  *  @return object returns a GuzzleHttp\Client object.
  */
 public function getRateSeries($from, $to, $dateStart, $dateEnd)
 {
     if ($this->settings['enable-cache']) {
         $api = $this->settings['api-source'];
         if (Cache::has("CConverter{$from}{$to}{$dateStart}{$dateEnd}")) {
             $result = Cache::get("CConverter{$from}{$to}{$dateStart}{$dateEnd}");
             $this->fromCache = true;
             if (Config::get('CConverter.enable-log')) {
                 Log::debug("Got currency rates from cache: CConverter{$from}{$to}{$dateStart}{$dateEnd}");
             }
         } else {
             if ($api === 'yahoo') {
                 return null;
             } else {
                 if ($api === 'openexchange') {
                     return null;
                     //$result = $this->openExchange($base);
                 } else {
                     if ($api === 'jsonrates') {
                         $result = $this->jsonRatesTimeSeries($from, $to, $dateStart, $dateEnd);
                     }
                 }
             }
             Cache::add("CConverter{$from}{$to}{$dateStart}{$dateEnd}", $result, $this->settings['cache-min']);
             $this->fromCache = false;
             if (Config::get('CConverter.enable-log')) {
                 Log::debug('Added new currency rates to cache: CConverter' . $api . $from . $to . $dateStart . $dateEnd . ' - for ' . $this->settings['cache-min'] . ' min.');
             }
         }
     } else {
         if ($api === 'yahoo') {
             return null;
         } else {
             if ($api === 'openexchange') {
                 return null;
                 //$result = $this->openExchange($base);
             } else {
                 if ($api === 'jsonrates') {
                     $result = $this->jsonRatesTimeSeries($from, $to, $dateStart, $dateEnd);
                 }
             }
         }
         $this->fromCache = false;
     }
     return $result;
 }
开发者ID:mean-cj,项目名称:Laravel-CConverter,代码行数:56,代码来源:Currency.php

示例12: getList

 /**
  * 分区信息
  *
  * @return $this
  */
 public function getList()
 {
     try {
         $tid = Input::get('tid', 0);
         $page = Input::get('page', 1);
         $order = Input::get('order', 'hot');
         $bili_util = new BiliUtil();
         if ($page == 1) {
             $cache_name = GlobalVar::$LIST_CACHE . $tid;
             if (!Cache::has($cache_name)) {
                 $back_json = $bili_util->getPageList($tid, $order, 1, GlobalVar::$PAGE_SIZE);
                 Cache::add($cache_name, $back_json, 60 * 60 * 2);
             } else {
                 $back_json = Cache::get($cache_name);
             }
         } else {
             $back_json = $bili_util->getPageList($tid, $order, $page, GlobalVar::$PAGE_SIZE);
         }
         $paginator = new Paginator($back_json['list'], $page);
         $paginator->setPath('/list');
         $sorts = CacheSetter::getSort();
         $hot = CacheSetter::getHot();
         return view('pusher.list')->with('sorts', $sorts)->with('list', $back_json['list'])->with("paginator", $paginator)->with('tid', $tid)->with('hots', $hot);
     } catch (Exception $e) {
         return view('pusher.error')->with('error_content', $e->getMessage());
     }
 }
开发者ID:bajian,项目名称:BiliPusher,代码行数:32,代码来源:HomeController.php

示例13: checkTotalQueueJobsVelocity

 public function checkTotalQueueJobsVelocity($queue_velocity_params, $connection = null)
 {
     foreach ($queue_velocity_params as $queue_name => $velocity_params) {
         // echo "checking queue $queue_name.  Now is ".Carbon::now()."\n";
         $service_id = $this->service_prefix . "queue_velocity_" . $queue_name;
         try {
             $minumum_velocity = $velocity_params[0];
             $time_description = $velocity_params[1];
             $now = Carbon::now();
             $old_time = Carbon::parse('-' . $time_description);
             $seconds_to_check = $old_time->diffInSeconds($now);
             $total_size_now = $this->getTotalQueueJobs($queue_name, $connection);
             $total_size_past = $this->getTotalQueueJobsInThePast($queue_name, $old_time);
             // echo "$queue_name \$now={$now} \$old_time={$old_time} \$total_size_now=".json_encode($total_size_now, 192)." \$total_size_past=".json_encode($total_size_past, 192)."\n";
             // cache $total_size_now
             $expires_at_time = $now->copy()->addSeconds($seconds_to_check)->addMinutes(10);
             $key = 'qTotalJobs_' . $queue_name . '_' . $now->format('Ymd_Hi');
             // echo "PUT key={$key} value=".json_encode($total_size_now, 192)." Expires at ".$expires_at_time."\n";
             Cache::add($key, $total_size_now, $expires_at_time);
             if ($total_size_past === null) {
                 // not enough information - pass for now
                 $this->consul_client->checkPass($service_id);
                 return;
             }
             try {
                 $actual_velocity = $total_size_now - $total_size_past;
                 // echo "$queue_name \$actual_velocity=$actual_velocity\n";
                 if ($actual_velocity >= $minumum_velocity) {
                     $this->consul_client->checkPass($service_id);
                 } else {
                     $this->consul_client->checkFail($service_id, "Queue {$queue_name} velocity was {$actual_velocity} in {$time_description}");
                 }
             } catch (Exception $e) {
                 Log::error($e->getMessage());
             }
         } catch (Exception $e) {
             try {
                 $this->consul_client->checkFail($service_id, $e->getMessage());
                 Log::error($e->getMessage());
             } catch (Exception $e) {
                 Log::error($e->getMessage());
             }
         }
     }
     return;
 }
开发者ID:tokenly,项目名称:consul-health-daemon,代码行数:46,代码来源:ServicesChecker.php

示例14: set

 public function set($key, $value)
 {
     Cache::add($key, $value, 5);
 }
开发者ID:abcn,项目名称:hhgapi,代码行数:4,代码来源:RedisStorage.php

示例15: withLock

 /**
  * Execute a callback function with a lock.
  *
  * Takes a callback function as a parameter, and only execute that callback function
  * once the lock has been acquired, or a timeout has passed.
  *
  * @param string   $key            Cache key.
  * @param callback $callback       Callback function.
  * @param integer  $timeousSeconds Timeout seconds.
  * @static
  * @access public
  * @return void
  */
 public static function withLock($key, $callback, $timeousSeconds = 10)
 {
     $start = time();
     $acquiredLock = false;
     while (time() - $start < $timeousSeconds && !$acquiredLock) {
         $acquiredLock = Cache::add(self::lockKey($key), time(), 1);
         if (!$acquiredLock) {
             usleep(100000);
         }
     }
     call_user_func($callback);
     Cache::forget(self::lockKey($key));
 }
开发者ID:ngmy,项目名称:cached-object,代码行数:26,代码来源:CachedObject.php


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