本文整理汇总了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;
}
}
示例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();
}
示例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;
}
示例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'));
}
示例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);
}
示例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);
}
}
示例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');
}
}
示例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'));
}
示例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);
}
示例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);
}
示例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;
}
}
示例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);
}
示例13: remember
public static function remember($key, $callback)
{
if (!Cache::has($key)) {
$value = $callback();
Cache::put($key, $value, 60);
}
return Cache::get($key);
}
示例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);
}
示例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;
}