本文整理汇总了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());
}
示例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();
});
}
示例3: getContactInfo
function getContactInfo()
{
$contactInfo = Cache::remember('contactusInfo', 20, function () {
return $this->first();
});
return $contactInfo;
}
示例4: karma
public static function karma()
{
$value = Cache::remember('statistics_karma', 5, function () {
return Vote::count();
});
return $value;
}
示例5: popular
public static function popular()
{
$populardata = Cache::remember('popular', 60, function () {
$data = Content::take(15)->orderBy('pageview', 'desc')->get();
return $data;
});
return $populardata;
}
示例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);
});
}
示例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;
}
示例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;
}
示例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';
}
示例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);
}
示例11: fetchAll
public function fetchAll()
{
$result = Cache::remember('post_cache', 1, function () {
return $this->get();
});
return $result;
}
示例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();
});
}
示例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];
}
示例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);
});
}
示例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);
}