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


PHP Cache::remember方法代碼示例

本文整理匯總了PHP中Illuminate\Support\Facades\Cache::remember方法的典型用法代碼示例。如果您正苦於以下問題:PHP Cache::remember方法的具體用法?PHP Cache::remember怎麽用?PHP Cache::remember使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Support\Facades\Cache的用法示例。


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

示例1: compose

 /**
  * Compose the view.
  *
  * @return void
  */
 public function compose(View $view)
 {
     $value = Cache::remember('users', 3, function () {
         return DB::table('users')->get();
     });
     $view->with('tags', Tags::all())->with('categories', Category::all());
 }
開發者ID:lyovkin,項目名稱:v2board,代碼行數:12,代碼來源:LeftAsideComposer.php

示例2: cachedPermissions

 /**
  * Tries to return all the cached permissions of the user
  * and if it can't bring the permissions from the cache,
  * it would bring them back from the DB
  * @return Illuminate\Database\Eloquent\Collection
  */
 public function cachedPermissions()
 {
     $cacheKey = 'laratrust_permissions_for_user_' . $this->getKey();
     return Cache::remember($cacheKey, Config::get('cache.ttl', 60), function () {
         return $this->permissions()->get();
     });
 }
開發者ID:santigarcor,項目名稱:laratrust,代碼行數:13,代碼來源:LaratrustUserTrait.php

示例3: getContactInfo

 function getContactInfo()
 {
     $contactInfo = Cache::remember('contactusInfo', 20, function () {
         return $this->first();
     });
     return $contactInfo;
 }
開發者ID:uusa35,項目名稱:ebook,代碼行數:7,代碼來源:Contactus.php

示例4: karma

 public static function karma()
 {
     $value = Cache::remember('statistics_karma', 5, function () {
         return Vote::count();
     });
     return $value;
 }
開發者ID:PovilasLT,項目名稱:maze,代碼行數:7,代碼來源:Statistics.php

示例5: popular

 public static function popular()
 {
     $populardata = Cache::remember('popular', 60, function () {
         $data = Content::take(15)->orderBy('pageview', 'desc')->get();
         return $data;
     });
     return $populardata;
 }
開發者ID:berkcekisbas,項目名稱:belirtileri,代碼行數:8,代碼來源:Layout.php

示例6: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     $key = $this->buildCacheKey($request);
     return Cache::remember($key, static::CACHE_MINUTES, function () use($request, $next) {
         return $next($request);
     });
 }
開發者ID:hussainweb,項目名稱:drupal-stats,代碼行數:14,代碼來源:CacheMiddleware.php

示例7: getActions

 /**
  * Actions allowed to be used on reports
  *
  * @return array
  */
 public function getActions()
 {
     $actions = Cache::remember('system.adkats.reports.actions', 60 * 12, function () {
         return Command::whereIn('command_id', static::$allowedCommands)->lists('command_name', 'command_id');
     });
     return $actions;
 }
開發者ID:BP4U,項目名稱:BFAdminCP,代碼行數:12,代碼來源:ReportRepository.php

示例8: getLatestBans

 /**
  * Gets the latest bans
  * @param  string  $cacheKey Caching key to use
  * @param  integer $ttl      Cache for X minutes
  * @return array
  */
 public function getLatestBans($cacheKey = 'bans.latest', $ttl = 1)
 {
     $bans = Cache::remember($cacheKey, $ttl, function () {
         return Ban::with('player', 'record')->latest(30)->get()->toArray();
     });
     return $bans;
 }
開發者ID:R3alflash,項目名稱:BFAdminCP,代碼行數:13,代碼來源:BanRepository.php

示例9: index

 /**
  * Create or update a note
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function index(Request $request)
 {
     $linehaul = $request->input('linehaul', null);
     $postalCode = $request->input('postalcode', null);
     $fresh = $request->input('fresh', false);
     $dummy = $request->input('dummy', false);
     //Damn strings
     if ($fresh == 'false') {
         $fresh = false;
     }
     if ($fresh) {
         $postalCodes = $this->getPostalCodes($linehaul, $postalCode);
     } else {
         $postalCodes = Cache::remember('postal_codes', 24 * 60, function () use($linehaul, $postalCode) {
             return $this->getPostalCodes($linehaul, $postalCode);
         });
     }
     if (!$dummy) {
         return Excel::create('PostalCodes' . Carbon::now()->toDateString(), function ($excel) use($postalCodes) {
             $excel->sheet('postalcodes', function ($sheet) use($postalCodes) {
                 $sheet->fromArray($postalCodes);
             });
         })->download('xls');
     }
     return 'DB UPDATED';
 }
開發者ID:dagmawiyehenew,項目名稱:laravel-levapp,代碼行數:32,代碼來源:PostalCodeController.php

示例10: compose

 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     $user = Cache::remember('user', 1440, function () {
         return Auth::user();
     });
     $view->with('user', $user);
 }
開發者ID:jespersgaard,項目名稱:tyloo,代碼行數:13,代碼來源:LoggedInUserViewComposer.php

示例11: fetchAll

 public function fetchAll()
 {
     $result = Cache::remember('post_cache', 1, function () {
         return $this->get();
     });
     return $result;
 }
開發者ID:onerciller,項目名稱:Laravel-es-redis-example,代碼行數:7,代碼來源:Post.php

示例12: cachedRoles

 /**
  * Tries to return all the cached roles of the user
  * and if it can't bring the roles from the cache,
  * it would bring them back from the DB
  * @return Illuminate\Database\Eloquent\Collection
  */
 public function cachedRoles()
 {
     $cacheKey = 'lumineer_roles_for_user_' . $this->getKey();
     return Cache::remember($cacheKey, Config::get('cache.ttl', 60), function () {
         return $this->roles()->get();
     });
 }
開發者ID:19peaches,項目名稱:lumineer,代碼行數:13,代碼來源:LumineerUserTrait.php

示例13: remember

 /**
  * Returns cached data after updating the cached value if expired
  *
  * @param  string  $key
  * @param  int     $ttl
  * @param  closure $closure
  * @return mixed
  */
 public static function remember($key, $ttl, $closure)
 {
     if (!isset(static::$cache[$key])) {
         static::$cache[$key] = parent::remember($key, $ttl, $closure);
     }
     return static::$cache[$key];
 }
開發者ID:carriercomm,項目名稱:sticky-notes,代碼行數:15,代碼來源:Cache.php

示例14: init

 /**
  * Init blogit.
  *
  * Fetch all files on the Github repository, transform and store them into
  * a collection of articles.
  *
  * @return void
  */
 protected function init()
 {
     if (config('blogit.cache')) {
         $documents = Cache::remember('documents', config('blogit.cache_expiration'), function () {
             return $this->documents->getAll();
         });
     } else {
         $documents = $this->documents->getAll();
     }
     // Make and push the new article into the collection.
     foreach ($documents as $document) {
         if (config('blogit.cache')) {
             $article = Cache::remember($document['sha'], config('blogit.cache_expiration'), function () use($document) {
                 return $this->makeArticle($document['path']);
             });
         } else {
             $article = $this->makeArticle($document['path']);
         }
         $this->collection->push($article);
     }
     // Set the previous and next articles for each article.
     $this->collection = $this->collection->each(function ($article, $key) {
         if (($previous = $this->collection->get($key - 1)) instanceof Article) {
             $article->setPrevious($previous);
         }
         if (($next = $this->collection->get($key + 1)) instanceof Article) {
             $article->setNext($next);
         }
     });
     // Set the related articles for each article.
     $this->collection = $this->collection->each(function ($article) {
         $related = $this->getRelatedArticlesByTags($article);
         $article->setRelatedArticles($related);
     });
 }
開發者ID:jrean,項目名稱:blogit,代碼行數:43,代碼來源:Blogit.php

示例15: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $fabricantes = Cache::remember('fabricantes', 15 / 60, function () {
         return Fabricante::simplePaginate(15);
     });
     return response()->json(['siguiente' => $fabricantes->nextPageUrl(), 'anterior' => $fabricantes->previousPageUrl(), 'datos' => $fabricantes->items()], 200);
 }
開發者ID:osvaldino,項目名稱:RESTful-API,代碼行數:12,代碼來源:FabricanteController.php


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