本文整理汇总了PHP中Illuminate\Cache\CacheManager::has方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheManager::has方法的具体用法?PHP CacheManager::has怎么用?PHP CacheManager::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Cache\CacheManager
的用法示例。
在下文中一共展示了CacheManager::has方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: has
/**
* Has
* @param $key
* @return bool
*/
public function has($key)
{
if ($this->cacheDriver == "file") {
return $this->cache->has($key);
}
return $this->cache->tags($this->tag)->has($key);
}
示例2: generate
/**
* Render weather widget.
*
* @param array $options
* @return string
*/
public function generate($options = array())
{
// Get options
$options = array_merge($this->config['defaults'], $options);
// Unify units
$options['units'] = strtolower($options['units']);
if (!in_array($options['units'], array('metric', 'imperial'))) {
$options['units'] = 'imperial';
}
// Create cache key
$cacheKey = 'Weather.' . md5(implode($options));
// Check cache
if ($this->config['cache'] && $this->cache->has($cacheKey)) {
return $this->cache->get($cacheKey);
}
// Get current weather
$current = $this->getWeather($options['query'], 0, $options['units'], 1);
if ($current['cod'] !== 200) {
return 'Unable to load weather';
}
// Get forecast
$forecast = $this->getWeather($options['query'], $options['days'], $options['units']);
// Render view
$html = $this->view->make("{$this->config['views']}.{$options['style']}", array('current' => $current, 'forecast' => $forecast, 'units' => $options['units'], 'date' => $options['date']))->render();
// Add to cache
if ($this->config['cache']) {
$this->cache->put($cacheKey, $html, $this->config['cache']);
}
return $html;
}
示例3: render
/**
* Render the homepage view for displaying.
*
* @param string $name
* @return string
*/
public function render($name, $subname = 'Home.Content')
{
if ($this->cache->has('home.content')) {
$content = $this->cache->get('home.content');
} else {
$slides = App::make('Lib\\Slides\\SlideRepository')->get();
$news = App::make('Lib\\News\\NewsRepository')->latest(8);
$content = $this->view->make($subname)->with('slides', $slides)->with('news', $news)->with('categories', $this->getCategories())->render();
$this->cache->put('home.content', $content, 2880);
}
return $this->view->make($name)->with('content', $content);
}
示例4: 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));
});
}
}
示例5: removeCacheLocale
/**
* Remove a locale from the cache.
*
* @param string $code
*/
protected function removeCacheLocale($code)
{
$id = sprintf('translation.%s', $code);
if ($this->cache->has($id)) {
$this->cache->forget($id);
}
}
示例6: compileScriptMaterial
/**
* @return \Illuminate\Support\Collection
*/
protected function compileScriptMaterial()
{
$files = new Collection();
$this->layoutJsMaterial->merge($this->defaultJsMaterial)->merge($this->extendJsMaterial)->each(function ($value) use($files) {
$files->push($this->findPath($value));
});
$code = md5($files);
$this->dispatcher->listen('kernel.handled', function () use($code, $files) {
$dictionary = new Collection();
$dictionary->push($this->application->publicPath());
$dictionary->push('cache');
$dictionary = $this->pathSplit($code, '2,2,2,2,2,2', $dictionary);
$dictionary = $dictionary->implode(DIRECTORY_SEPARATOR);
if (!$this->files->isDirectory($dictionary)) {
$this->files->makeDirectory($dictionary, 0755, true, true);
}
$file = $dictionary . DIRECTORY_SEPARATOR . Str::substr($code, 12, 20) . '.js';
$key = 'cache.script.' . $code;
if (!$this->files->exists($file) || !$this->cache->has($key) && $this->application->inDebugMode()) {
$content = $this->compileScript($files);
$expires = Carbon::now()->addMinutes(10);
$this->cache->put($key, $content, $expires);
file_put_contents($file, $content);
}
});
return $this->pathSplit($code, '2,2,2,2,2,2,20', Collection::make(['cache']))->implode('/') . '.js';
}
示例7: getPrice
/**
* Return the price of an item using Steam's API
*
* @param integer $appId
* @param string $itemName
* @param bool $onlyPrice Return only the lowest price
* @return stdClass
*/
public function getPrice($appId = 730, $itemName, $onlyPrice = false)
{
$cacheKey = 'steamprice.item.' . str_slug($itemName);
// Check if item price is cached
if ($this->cache->has($cacheKey)) {
$data = $this->cache->get($cacheKey);
} else {
// Grab the item price and cache it
$url = $this->getItemPriceUrl($itemName, $appId);
// No result
if (!($json = @file_get_contents($url))) {
// Cache null for 30 seconds to not harass the Steam servers
$this->cache->put($cacheKey, null, 30);
return null;
}
$json = str_replace($this->currencyHtmlTags, '', $json);
$data = json_decode($json);
$this->cache->put($cacheKey, $data, Config::get('braseidon.steam-item-prices.cache_time'));
}
if ($onlyPrice === true) {
$data = !isset($data->lowest_price) ? null : $data->lowest_price;
}
return $data;
}
示例8: has
/**
* Check if the cache has a key
*
* @param string $key
*
* @return bool
*/
public function has($key)
{
return $this->cache->has($key);
}
示例9: isCached
/**
* @return bool
*/
public function isCached()
{
return $this->getUseCache() && $this->cache->has($this->getCacheKey());
}
示例10: has
/**
* Checks if a setting exists.
*
* @param string $key
* @return boolean
*/
public function has($key)
{
return (bool) $this->cache->has($this->key($key));
}
示例11: verifyHandled
/**
* Verify that the request hasn't been handled yet
*
* @return Boolean
*/
protected function verifyHandled()
{
return !$this->cache->has($this->getCacheKey());
}
示例12: forgetMenuMapByKey
/**
* forgetMenuMapByKey
*
* @param string $menuKey to forget on menu map
*
* @return void
*/
public function forgetMenuMapByKey($menuKey)
{
$menuMap = [];
if ($this->cache->has($this->menuMapKey)) {
$oldMenuMap = $this->cache->get($this->menuMapKey);
foreach ($oldMenuMap as $key => $value) {
if ($key !== $menuKey && $key !== $value) {
$menuMap[$key] = $value;
}
}
}
$this->cache->forever($this->menuMapKey, $menuMap);
}