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