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


PHP Cache::put方法代碼示例

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


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

示例1: prettifyOnlineStatus

 public function prettifyOnlineStatus($presence, $accounts)
 {
     $key = 'online_status';
     if (Cache::has($key)) {
         return Cache::get($key);
     } else {
         $user_string = '<strong>Online Status</strong><br/>';
         $found = false;
         foreach ($presence as $seo => $response) {
             $data = json_decode($response->getBody(), true);
             if (isset($data['state']) && $data['state'] == "Online") {
                 foreach ($data['devices'] as $device) {
                     if ($device['type'] == "XboxOne") {
                         foreach ($device['titles'] as $title) {
                             if (in_array($title['id'], $this->acceptedGameIds)) {
                                 $found = true;
                                 $gt = $accounts->where('seo', $seo)->first();
                                 $user_string .= "<strong>" . $gt->gamertag . ": </strong>" . $title['name'];
                                 if (isset($title['activity'])) {
                                     $user_string .= " (" . $title['activity']['richPresence'] . ")";
                                 }
                                 $user_string .= "<br/>";
                             }
                         }
                     }
                 }
             }
         }
         if (!$found) {
             $user_string = 'No-one is online. Pity us.';
         }
         Cache::put($key, $user_string, 5);
         return $user_string;
     }
 }
開發者ID:GMSteuart,項目名稱:PandaLove,代碼行數:35,代碼來源:Client.php

示例2: schedule

 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->call(function () {
         Cache::put('last-cron', new Carbon(), 5);
     })->everyMinute();
     $schedule->command('inspire')->hourly();
 }
開發者ID:atrauzzi,項目名稱:laravel-drydock,代碼行數:13,代碼來源:Kernel.php

示例3: tableToArray

 /**
  * Return a simple list of entries in the table.
  *
  * May cache the results for up to 60 minutes.
  *
  * @return	array of Fluent objects
  */
 public static function tableToArray()
 {
     $me = new static();
     $cache_key = $me->cacheKey();
     // Return the array from the cache if it is present.
     if (Cache::has($cache_key)) {
         return (array) Cache::get($cache_key);
     }
     // Otherwise put the results into the cache and return them.
     $results = [];
     $query = static::all();
     // If the current model uses softDeletes then fix the
     // query to exclude those objects.
     foreach (class_uses(__CLASS__) as $traitName) {
         if ($traitName == 'SoftDeletes') {
             $query = static::whereNull('deleted_at')->get();
             break;
         }
     }
     /** @var Cacheable $row */
     foreach ($query as $row) {
         $results[$row->getIndexKey()] = $row->toFluent();
     }
     Cache::put($cache_key, $results, 60);
     return $results;
 }
開發者ID:delatbabel,項目名稱:keylists,代碼行數:33,代碼來源:Cacheable.php

示例4: compose

 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     if (!Cache::get('popular_categories')) {
         Cache::put('popular_categories', $this->categories->getPopular(), 60);
     }
     $view->with('popular_categories', Cache::get('popular_categories'));
 }
開發者ID:ambarsetyawan,項目名稱:brewski,代碼行數:13,代碼來源:PopularCategoriesComposer.php

示例5: handle

 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // Session used to check roles inside the views
     //FIRST :: SESSION(ROLE.ID)
     // SECOND CACHE(MODULES.ID
     // THIRD :: CACHE(ABILITIES.ID
     // FOURTH  CACHE(AUTHOR/ADMIN/EDITOR.ID
     // FIFTH CACHE(ROLE.ID
     $this->userRoles = $this->user->roles()->first();
     $authUserRole = $this->user->roles()->first();
     Session::put('ROLE.' . Auth::id(), $authUserRole->id);
     Session::put('ROLE.' . $authUserRole->name, md5($authUserRole->id));
     $modules = $this->userRoles->perms()->where('level', '=', '1');
     $modulesList = $modules->lists('name', 'id')->toArray();
     // abilitiles = modules + permissions
     $abilities = $this->userRoles->perms()->get();
     $abilitiesList = $abilities->Lists('name', 'id')->toArray();
     // ROLE.AUTHOR/ADMIN/EDITOR
     Cache::put(strtoupper($authUserRole->name) . Auth::id(), $authUserRole->name, 99999999);
     // GET USER ROLE
     Cache::put('ROLE.' . Auth::id(), $authUserRole->name, 99999999);
     /*
      * 'Module.ID' => [List of Modules]
      * */
     Cache::put('MODULES.' . Auth::id(), array_values($modulesList), 99999999);
     /*
      * All Permissions and Roles in one array
      *
      * */
     Cache::put('ABILITIES.' . Auth::id(), array_values($abilitiesList), 99999999);
 }
開發者ID:uusa35,項目名稱:ebook,代碼行數:36,代碼來源:CollectCacheDataForAuthUser.php

示例6: put

 public function put(Route $route, Request $request, Response $response)
 {
     $key = $this->makeCacheKey($request->url());
     if (!Cache::has($key)) {
         Cache::put($key, $response->getContent(), 10);
     }
 }
開發者ID:RichJones22,項目名稱:TimeTrax,代碼行數:7,代碼來源:CacheFilters.php

示例7: render

 public function render($format = 'atom', $cache = FALSE, $cacheTime = 3600)
 {
     $channel = $this->channel;
     $channel->pubdate = $this->formatDate($this->channel->pubdate, $format);
     $items = $this->items;
     foreach ($items as $item) {
         $item->pubdate = $this->formatDate($item->pubdate, $format);
     }
     if ($format == 'atom') {
         $this->content_type = 'application/atom+xml';
     } else {
         $this->content_type = 'application/rss+xml';
     }
     if ($cache == TRUE && Cache::has('feed-' . $format)) {
         return response()->view('feed::' . $format, Cache::get('feed-' . $format))->header('Content-Type', $this->content_type)->header('Content-Type', 'text/xml');
     } elseif ($cache == TRUE) {
         Cache::put('feed-' . $format, compact('channel', 'items'), $cacheTime);
         return response()->view('feed::' . $format, compact('channel', 'items'))->header('Content-Type', $this->content_type)->header('Content-Type', 'text/xml');
     } elseif ($cache == FALSE && Cache::has('feed-' . $format)) {
         Cache::forget('feed-' . $format);
         return response()->view('feed::' . $format, compact('channel', 'items'))->header('Content-Type', $this->content_type)->header('Content-Type', 'text/xml');
     } else {
         return response()->view('feed::' . $format, compact('channel', 'items'))->header('Content-Type', $this->content_type)->header('Content-Type', 'text/xml');
     }
 }
開發者ID:zogxray,項目名稱:simple-laravel-feed,代碼行數:25,代碼來源:Feed.php

示例8: compose

 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     if (!Cache::get('recent_posts')) {
         Cache::put('recent_posts', $this->posts->getAll('published', null, 'published_at', 'desc', 5), 10);
     }
     $view->with('recent_posts', Cache::get('recent_posts'));
 }
開發者ID:ambarsetyawan,項目名稱:brewski,代碼行數:13,代碼來源:RecentPostsComposer.php

示例9: generateCache

 public static function generateCache($public_key, \AccessLevel $accessLevel)
 {
     $expiresAt = self::generateExpiration($accessLevel->interval_type, $accessLevel->interval_value);
     // if no cache, create one with total and remain as the same
     $cache = ['total' => $accessLevel->request_limit, 'remaining' => $accessLevel->request_limit, 'expires_at' => $expiresAt->toDateTimeString()];
     Cache::put($public_key, json_encode($cache), 0);
 }
開發者ID:ryanmcoble,項目名稱:remedy,代碼行數:7,代碼來源:RateLimiter.php

示例10: installK2

 public function installK2(StoreK2Request $request, MessagingResource $resource)
 {
     // TODO: this cannot be hardcoded, depends on resource type
     // Also make sure that by injecting a crafted resource id it won't be possible to override other keys!
     Cache::put("K2_SLOT_" . $resource->getResourceId(), $request->k2->toJson(), 0);
     return response(null, 204);
 }
開發者ID:nicolacimmino,項目名稱:RIoT,代碼行數:7,代碼來源:KeysController.php

示例11: blacklist

 public function blacklist()
 {
     if (!$this->isBlacklisted()) {
         $expiresAt = Carbon::createFromTimestamp($this->get()->exp);
         Cache::put($this->jti(), $this->jti(), $expiresAt);
         $this->status = self::BLACKLISTED_TOKEN;
     }
 }
開發者ID:lucasromanojf,項目名稱:jwt-guard,代碼行數:8,代碼來源:CommonJWT.php

示例12: updateSessionCookie

 /**
  * 更新緩存cookie
  * @param $setCookies
  */
 public function updateSessionCookie($setCookies)
 {
     $cacheCookie = $this->getSessionCookie();
     $setCookie = str_replace(' ', '+', $this->getSetCookie($setCookies));
     $mergeCookie = $this->cookieStr2Arr($setCookie) + $this->cookieStr2Arr($cacheCookie);
     $newCookie = $this->cookieArr2Str($mergeCookie);
     Cache::put($this->getCacheKey(), $newCookie, PazxConst::CACHE_EXPIRES_MINUTES);
 }
開發者ID:zhangzijun,項目名稱:diandian,代碼行數:12,代碼來源:Session.php

示例13: remember

 public static function remember($key, $callback)
 {
     if (!Cache::has($key)) {
         $value = $callback();
         Cache::put($key, $value, 60);
     }
     return Cache::get($key);
 }
開發者ID:kcwikizh,項目名稱:kcwiki-api,代碼行數:8,代碼來源:Util.php

示例14: put

 public function put($key, $data, $cacheMinutes = null)
 {
     if (!$cacheMinutes) {
         $cacheMinutes = self::CACHE_MINUTES;
     }
     $expiresAt = Carbon::now()->addMinutes($cacheMinutes);
     Cache::put($key, $data, $expiresAt);
 }
開發者ID:samhoud,項目名稱:eventbrite-plugin,代碼行數:8,代碼來源:EventbriteCache.php

示例15: handle

 /**
  * After request. If the cache key not exist. Cache the contents
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $response = $next($request);
     $key = $this->makeCacheKey($request->url());
     if (!Cache::has($key)) {
         Cache::put($key, $response->getContent(), 60);
     }
     return $response;
 }
開發者ID:lihaoxiang1989,項目名稱:Marlabs-notes,代碼行數:16,代碼來源:AfterCache.php


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