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; } }
/** * 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(); }
/** * 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; }
/** * 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')); }
/** * 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); }
public function put(Route $route, Request $request, Response $response) { $key = $this->makeCacheKey($request->url()); if (!Cache::has($key)) { Cache::put($key, $response->getContent(), 10); } }
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'); } }
/** * 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')); }
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); }
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); }
public function blacklist() { if (!$this->isBlacklisted()) { $expiresAt = Carbon::createFromTimestamp($this->get()->exp); Cache::put($this->jti(), $this->jti(), $expiresAt); $this->status = self::BLACKLISTED_TOKEN; } }
/** * 更新缓存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); }
public static function remember($key, $callback) { if (!Cache::has($key)) { $value = $callback(); Cache::put($key, $value, 60); } return Cache::get($key); }
public function put($key, $data, $cacheMinutes = null) { if (!$cacheMinutes) { $cacheMinutes = self::CACHE_MINUTES; } $expiresAt = Carbon::now()->addMinutes($cacheMinutes); Cache::put($key, $data, $expiresAt); }
/** * 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; }
public function touch() { if (Cache::has('mtime:' . $this->name)) { $time = time(); Cache::put('mtime:' . $this->name, $time); return $time; } return FALSE; }
/** * Show the application welcome screen to the user. * * @return Response */ public function index() { if (Cache::has('products:all')) { $products = Cache::get('products:all'); } else { $products = Products::all(); Cache::put('products:all', $products, 15); } return view('index', compact("products")); }
public static function recordar($titulo, $otro) { if (Cache::has($titulo)) { // return Cache::get($titulo); } else { Cache::put($titulo, $otro, 60); return $otro; } }
public function allowed($procedure) { $key = $procedure . ':' . Request::ip() . ':lockout'; $decayMinutes = (int) config('auth.email_lockout') ?: -1; if (!Cache::has($key)) { Cache::put($key, '', $decayMinutes); return true; } return false; }
/** * 该API用于获取预授权码。 * 预授权码用于公众号授权时的第三方平台方安全验证。 * * @return mixed */ public function createPreAuthCode() { return Cache::get($this->preAuthCodeCacheKey, function () { $response = $this->http->jsonPost(self::API_CREATE_PREAUTHCODE, ['component_appid' => $this->appid]); $pre_auth_code = $response['pre_auth_code']; // 把pre_auth_code缓存起来 $expiresAt = Carbon::now()->addSeconds($response['expires_in']); Cache::put($this->preAuthCodeCacheKey, $pre_auth_code, $expiresAt); return $pre_auth_code; }); }
/** * Execute the job. * * @return void */ public function handle() { $userRole = $this->request->user()->roles()->first(); Session::put('ROLE.' . Auth::id(), $userRole->id); Cache::get('ROLE.' . Auth::id(), $userRole->name, 9999999); $modules = $userRole->perms()->where('level', '=', '1')->get(); $modulesList = $modules->lists('name', 'id')->toArray(); Cache::put('MODULES.' . Auth::id(), array_values($modulesList), 9999999); $userAbilities = $userRole->perms()->get()->lists('name', 'id')->toArray(); Cache::put('ABILITIES.' . Auth::id(), array_values($userAbilities), 9999999); }
public function getDepartments() { if (!Cache::has('departments')) { $departments = Department::active()->sort()->with('langs')->get(); $departments = $this->loadLangs($departments); Cache::put('departments', $departments, Carbon::now()->addHour()); } else { $departments = Cache::get('departments'); } return $departments; }
public function handle() { if ($this->attempts() > 5) { $this->delete(); } Mail::send('test_email', ['note' => $this->message], function (Message $message) { $message->from('laravel.drydock@localhost'); $message->to($this->email, 'Development User'); $message->subject('Test job completed!'); }); Cache::put('last-message', $this->message, 5); }
public function blacklist() { if (!$this->isBlacklisted()) { $expiresAt = Carbon::createFromTimestamp($this->get()->exp); Cache::put($this->jti(), $this->jti(), $expiresAt); if (isset($this->get()->rti)) { $refreshTokenExpiresAt = Carbon::createFromTimestamp($this->get()->iat + $this->get()->rtd); Cache::put($this->rti(), $this->rti(), $refreshTokenExpiresAt); } $this->status = self::BLACKLISTED_TOKEN; } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($slug) { if (Cache::has('article')) { $article = Cache::get('article'); } else { $article = Article::where('slug', $slug)->first(); Cache::put('article', $article, 120); } $categories = Category::all(); $tags = Tag::all(); return view('articles.show', compact('article', 'categories', 'tags')); }
public function deny() { $allowedRooms = 'tattler:access:' . $this->sessionId; $myRooms = Cache::get($allowedRooms); if (!$myRooms) { $myRooms = []; } if (isset($myRooms[$this->name])) { unset($myRooms[$this->name]); } return Cache::put($allowedRooms, $myRooms, Carbon::now()->addDay()); }
/** * Determine if the user has too many failed login attempts. * * @param \Illuminate\Http\Request $request * @return bool */ protected function hasTooManyLoginAttempts(Request $request) { $attempts = $this->getLoginAttempts($request); $lockedOut = Cache::has($this->getLoginLockExpirationKey($request)); if ($attempts > $this->maxLoginAttempts() || $lockedOut) { if (!$lockedOut) { Cache::put($this->getLoginLockExpirationKey($request), time() + $this->lockoutTime(), 1); } return true; } return false; }
/** * Display a listing of the resource. * * @return Response */ public function index() { if (Cache::has('offer-data')) { $data = Cache::get('offer-data'); return view('account.offers.list', $data); } $offers = Offer::paginate(6); $data = ['offers' => $offers]; $expiresAt = Carbon::now()->addMinutes(5); Cache::put('offer-data', $data, $expiresAt); return view('account.offers.list', $data); }
/** * * @return type XML contendo o ultimo indice do IGP-M */ public function getUltimoIndiceXML() { $cacheKey = 'index' . $this->serieCode; $value = Cache::get($cacheKey, null); if ($value == null) { $conf[0] = 'getUltimoValorXML'; $conf[1] = array('codigoSerie' => $this->serieCode); $value = $this->getData($conf); Cache::put($cacheKey, $value, Config::get('INDEX_CACHE_TIMEOUT', 120)); } return $value; }
/** * 获取颜色列表 * * @return array */ public function lists() { $key = 'gibson.wechat.colors'; // for php 5.3 $http = $this->http; $apiList = self::API_LIST; return Cache::get($key, function ($key) use($http, $apiList) { $result = $http->get($apiList); Cache::put($key, $result['colors'], 86400); // 1 day return $result['colors']; }); }