本文整理汇总了PHP中Cache::rememberForever方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::rememberForever方法的具体用法?PHP Cache::rememberForever怎么用?PHP Cache::rememberForever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::rememberForever方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setting
/**
* Get setting
*
* @param $name
* @return mixed
*/
function setting($name)
{
$settings = Cache::rememberForever('settings', function () {
return Setting::select('name', 'value')->get();
});
return $settings->where('name', $name)->first();
}
示例2: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$json = \Cache::rememberForever('categories_json', function () {
return ['data' => ['categories' => Category::categoryAsc()->get()]];
});
return \Response::json($json);
}
示例3: setupReports
protected function setupReports($view)
{
$reportsCount = Cache::rememberForever('reportsCount', function () {
return Report::count();
});
$view->with('reportsCount', $reportsCount);
}
示例4: getOrderBy
public static function getOrderBy()
{
$tagsOrderBy = Cache::rememberForever('tagsOrderBy', function () {
return ['id', 'asc'];
});
return $tagsOrderBy;
}
示例5: index
public function index()
{
$gioithieu = Cache::rememberForever('gioithieu_cache', function () {
return $this->model->gioithieu();
});
return View::make('pages.gioithieu')->with(compact('gioithieu'));
}
示例6: middleOfTheWorld
public function middleOfTheWorld()
{
$tour = Cache::rememberForever('middleOfTheWorld', function () {
return Tour::first();
});
//$tour = Tour::first();
return View::make('tours.middle-of-the-world', compact('tour'));
}
示例7: profileImage
function profileImage($id, $width = 128, $height = 128)
{
$image = \Cache::rememberForever("userprofile-{$id}-{$width}-x-{$height}", function () use($id, $width, $height) {
$img = DataSource::keystone_exec("_layouts/StPeters.Keystone/_shared/avatarhandler.ashx?id={$id}&w={$width}&h={$height}");
return $img;
});
return \Response::make($image, 200, array('content-type' => 'image/jpg'));
}
示例8: index
public function index()
{
$contact = Cache::rememberForever('contact_cache', function () {
return $this->model->contact();
});
$map = $this->model->contact_map();
$map = json_decode($map);
return View::make('pages.lienhe')->with(compact('contact', 'map'));
}
示例9: compose
public function compose(View $view)
{
if (!config('administr.hasLanguages')) {
return;
}
$languages = \Cache::rememberForever('languages_list', function () {
return Language::pluck('code', 'id');
});
$view->with('languages', $languages);
}
示例10: zedx_cache
/**
* Cache a closure forever.
*
* @param string $key
* @param \Closure $next
*
* @return \Closure
*/
function zedx_cache($key, Closure $next)
{
if (!env('APP_CACHE', true)) {
return $next();
}
return Cache::rememberForever("zx-{$key}", function () use($next) {
\Log::info('yes');
return $next();
});
}
示例11: loadCategories
public function loadCategories()
{
$categories = null;
if (\Cache::has(Category::cache_key)) {
$categories = \Cache::get(Category::cache_key);
} else {
$categories = \Cache::rememberForever(Category::cache_key, function () {
return Category::lists('title', 'slug');
});
}
\View::share('app_categories', $categories);
}
示例12: names
protected function names()
{
$cache_id = 'emoji-names';
$loader = function () {
$dir = app('path.public') . self::PATH;
foreach (glob($dir . '/*.png') as $file) {
$names[] = pathinfo($file, PATHINFO_FILENAME);
}
return $names;
};
if ('production' == App::environment()) {
return Cache::rememberForever($cache_id, $loader);
} else {
return call_user_func($loader);
}
}
示例13: config
/**
* Gets or sets the site configuration data
*
* @access public
* @param string $group
* @param array $newData
* @return stdClass|bool
*/
public static function config($group = '', $newData = FALSE)
{
// Get a config value
if ($newData === FALSE) {
$config = Cache::rememberForever('site.config', function () {
$config = Config::get('default');
if (Schema::hasTable('config')) {
$siteConfig = Site::all();
if (!is_null($siteConfig)) {
foreach ($siteConfig as $item) {
$config[$item['group']]->{$item}['key'] = $item['value'];
}
}
}
return $config;
});
return empty($group) ? (object) $config : $config[$group];
} else {
$site = static::config('general');
// Get the tags that have HTML content
$htmlKeys = preg_split('/\\||,/', $site->htmlKeys);
// Update the new config values in the DB
foreach ($newData as $key => $value) {
// Check for and strip HTML content
if (in_array($key, $htmlKeys)) {
$value = strip_tags($value, $site->allowedTags);
}
// Save config data
if (!empty($key) and !starts_with($key, '_')) {
$key = camel_case($key);
// Get the existing value of the config
$config = static::query();
$config->where('group', $group);
$config->where('key', $key);
// Do an UPSERT, i.e. if the value exists, update it.
// If it doesn't, insert it.
if ($config->count() > 0) {
$config->update(array('value' => $value));
} else {
$config->insert(array('group' => $group, 'key' => $key, 'value' => $value));
}
}
}
Cache::flush();
return TRUE;
}
}
示例14: globalParams
function globalParams($key = null, $default = false)
{
$params = [];
try {
$params = Cache::rememberForever('global_params', function () {
if (!Schema::hasTable('settings')) {
return collect();
}
return Setting::get();
});
$params = $params->groupBy('site_id')->toArray();
} catch (\Exception $e) {
}
$siteId = site()->id;
$params = isset($params[$siteId]) ? collect($params[$siteId])->pluck('value', 'key') : [];
if ($key == null) {
return $params;
}
return isset($params[$key]) ? $params[$key] : $default;
}
示例15: createInstance
protected static function createInstance()
{
if (config('app.debug') && !config('trans.cache_on_debug')) {
\Cache::forget('po_cache');
}
return \Cache::rememberForever('po_cache', function () {
$basePath = config('trans.translations_path');
$locales = config('trans.supported_locales');
$translator = new SymfonyTranslator(config('app.locale'));
$translator->addLoader('po', new PoFileLoader());
$translator->setFallbackLocales([config('app.locale')]);
foreach ($locales as $locale) {
$path = base_path($basePath . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES');
$file = $path . DIRECTORY_SEPARATOR . 'messages.po';
if (file_exists($file)) {
$translator->addResource('po', $file, $locale);
$translator->getCatalogue($locale);
}
}
return $translator;
});
}