本文整理汇总了PHP中Illuminate\Cache\CacheManager::remember方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheManager::remember方法的具体用法?PHP CacheManager::remember怎么用?PHP CacheManager::remember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Cache\CacheManager
的用法示例。
在下文中一共展示了CacheManager::remember方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lookup
/**
* Lookup an item in the API.
*
* @param string $item
* @param array $params
*
* @return object
*/
public function lookup($id, $value = null, $params = array())
{
$cacheKey = $this->cacheKey('lookup', $this->getLookupParams($id, $value, $params));
$cacheDuration = $this->iTunesConfig['cache'];
if ($this->cache->has($cacheKey)) {
return $this->cache->get($cacheKey);
} else {
return $this->cache->remember($cacheKey, $cacheDuration, function () use($id, $value, $params) {
return json_encode(parent::lookup($id, $value, $params));
});
}
}
示例2: cache
/**
* Execute caching against database query.
*
* @see config/project.php's cache section.
*
* @param string $key
* @param int $minutes
* @param \App\Model|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
* |\Illuminate\Database\Eloquent\Relations\Relation $query
* @param string $method
* @param mixed ...$args
* @return mixed
*/
protected function cache($key, $minutes, $query, $method, ...$args)
{
$args = !empty($args) ? implode(',', $args) : null;
if (config('project.cache') === false) {
return $query->{$method}($args);
}
return $this->cache->remember($key, $minutes, function () use($query, $method, $args) {
return $query->{$method}($args);
});
}
示例3: showDashboard
/**
* Return the admin dashboard view.
*
* @return \Illuminate\View\View
*/
public function showDashboard(CacheManager $cache)
{
$stats = ['Item stats' => ['Listed' => function ($range) use($cache) {
return mustard_number($cache->remember('total_items', config('mustard.dashboard_cache'), function () use($range) {
return Item::totalListed($range);
}));
}, 'Watched' => function ($range) use($cache) {
return mustard_number($cache->remember('total_items', config('mustard.dashboard_cache'), function () use($range) {
return Item::totalWatched($range);
}));
}], 'User stats' => ['Registered' => function ($range) use($cache) {
return mustard_number($cache->remember('total_users', config('mustard.dashboard_cache'), function () use($range) {
return User::totalRegistered($range);
}));
}, 'Sellers' => function ($range) use($cache) {
return mustard_number($cache->remember('total_sellers', config('mustard.dashboard_cache'), function () use($range) {
return User::totalSellers($range);
}));
}]];
if (mustard_loaded('auctions')) {
$stats['User stats']['Bidders'] = function ($range) use($cache) {
return mustard_number($cache->remember('total_bidders', config('mustard.dashboard_cache'), function () use($range) {
return User::totalBidders($range);
}));
};
$stats['Item stats']['Bids placed'] = function ($range) use($cache) {
return mustard_number($cache->remember('total_bids_placed', config('mustard.dashboard_cache'), function () use($range) {
return \Hamjoint\Mustard\Auctions\Bid::totalPlaced($range);
}));
};
$stats['Item stats']['Average bid amount'] = function ($range) use($cache) {
return mustard_price($cache->remember('average_bids', config('mustard.dashboard_cache'), function () use($range) {
return \Hamjoint\Mustard\Auctions\Bid::averageAmount($range);
}));
};
}
if (mustard_loaded('commerce')) {
$stats['User stats']['Buyers'] = function ($range) use($cache) {
return mustard_number($cache->remember('total_buyers', config('mustard.dashboard_cache'), function () use($range) {
return User::totalBuyers($range);
}));
};
$stats['Transaction stats']['Purchases'] = function ($range) use($cache) {
return mustard_number($cache->remember('total_purchases', config('mustard.dashboard_cache'), function () use($range) {
return \Hamjoint\Mustard\Commerce\Purchase::totalCreated($range);
}));
};
$stats['Transaction stats']['Average amount'] = function ($range) use($cache) {
return mustard_price($cache->remember('average_purchases', config('mustard.dashboard_cache'), function () use($range) {
return \Hamjoint\Mustard\Commerce\Purchase::averageAmount($range);
}));
};
}
$ranges = ['Today' => strtotime('midnight'), 'This week' => strtotime('monday this week'), 'This month' => strtotime('midnight first day of this month'), 'This year' => strtotime(date('Y') . '/01/01'), 'Overall' => 0];
return view('mustard::admin.dashboard', ['ranges' => $ranges, 'stats' => $stats]);
}
示例4: render
/**
* @return \Illuminate\Http\Response
*/
public function render()
{
if ($this->getUseCache()) {
$data = $this->cache->remember($this->getCacheKey(), $this->getCacheLifetime(), function () {
return $this->buildXML();
});
} else {
$data = $this->buildXML();
}
$headers = ['Content-type' => 'text/xml; charset=utf-8'];
return new Response($data, 200, $headers);
}
示例5: registerCollectionCache
/**
* Register the collections cache and store each of the cached items on
* the collection.
*
* @return \JasonLewis\Website\DocumentCollection
*/
public function registerCollectionCache()
{
// If the cache does not contain the items identifier then we'll use the loader
// to load all items and store the items in the cache.
$items = $this->cache->remember($this->identifier, $this->expires, function () {
$items = $this->loader->load();
// Spin over each of the items and store the individual articles in the cache
// as well so that when we request a single item we can quickly pull it from
// the cache.
foreach ($items as $item) {
$this->cache->put($item->getSlug(), $item, $this->expires);
}
return $items;
});
// With the cached items we'll now spin over each one and using the array access
// assign it to our document collection.
foreach ($items as $item) {
$this[$item->getSlug()] = $item;
}
return $this;
}
示例6: setRates
/**
* Downloads the latest exchange rates file from openexchangerates.org
*
* @return object
*/
public function setRates()
{
// Avoid instance issues
$self = $this;
// Cache the currencies
return $this->rates = $this->cache->remember('currencies', $this->getExpires(), function () use($self) {
if (!($appId = $self->getAppId())) {
throw new Exception('OpenExchangeRates.org requires an app key.');
}
$client = new Client(['base_url' => $self->getUrl()]);
$data = $client->get("latest.json?app_id={$appId}")->json();
return $data['rates'];
});
}