本文整理汇总了PHP中Illuminate\Support\Facades\Cache::rememberForever方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::rememberForever方法的具体用法?PHP Cache::rememberForever怎么用?PHP Cache::rememberForever使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Cache
的用法示例。
在下文中一共展示了Cache::rememberForever方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rememberForever
/**
* Returns cached data after updating the cached value if expired
*
* @param string $key
* @param closure $closure
* @return mixed
*/
public static function rememberForever($key, $closure)
{
if (!isset(static::$cache[$key])) {
static::$cache[$key] = parent::rememberForever($key, $closure);
}
return static::$cache[$key];
}
示例2: boot
/**
* Bootstrap the application services.
*/
public function boot()
{
parent::boot();
$this->publishMigrations();
$app = $this->app;
if ($app->bound('form')) {
$app->form->macro('selectCountry', function ($name, $selected = null, $options = []) use($app) {
$countries = Cache::rememberForever('brianfaust.countries.select.name.cca2', function () {
$records = Country::get(['name', 'cca2']);
$countries = new Collection();
$records->map(function ($item) use(&$countries) {
$countries[$item['cca2']] = $item['name']['official'];
});
return $countries->sort();
});
return $app->form->select($name, $countries, $selected, $options);
});
$app->form->macro('selectCountryWithId', function ($name, $selected = null, $options = []) use($app) {
$countries = Cache::rememberForever('brianfaust.countries.select.id.cca2', function () {
$records = Country::get(['name', 'id']);
$countries = new Collection();
$records->map(function ($item) use(&$countries) {
$countries[$item['id']] = $item['name']['official'];
});
return $countries->sort();
});
return $app->form->select($name, $countries, $selected, $options);
});
}
}
示例3: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$system = Cache::rememberForever('systemSetting', function () {
return (object) $this->settingRepository->first()->toArray();
});
return view('dashboard.system_setting.index', compact('system'));
}
示例4: getAllTagsForContentType
public function getAllTagsForContentType($contentType)
{
return Cache::rememberForever('tags_all_content_type_' . $contentType, function () use($contentType) {
$contentTypeId = $this->getContentTypeId($contentType);
$hashIdsForContentTypeId = $this->getHashIdsForContentTypeId($contentTypeId);
$distinctTags = $this->getDistinctTagsFromHashIds($hashIdsForContentTypeId);
return $distinctTags;
});
}
示例5: get
public function get()
{
if (!Cache::has('settings')) {
Cache::rememberForever('settings', function () {
return $this->setting->first();
});
}
return Cache::get('settings');
}
示例6: compose
/**
* @param View $view
*/
public function compose(View $view)
{
if (!Cache::has('this_user')) {
Cache::rememberForever('this_user', function () {
return $this->user->thisUser($this->auth->user()->id);
});
}
$view->with('user', Cache::get('this_user'));
}
示例7: provider
public function provider()
{
return function ($app) {
$parsedRoutes = Cache::rememberForever('haljson.mapping', function () use($app) {
return $this->parseRoutes(new Mapper($app['config']->get('haljson')));
});
return new HalJsonSerializer(new HalJsonTransformer($parsedRoutes));
};
}
示例8: getRoleId
public function getRoleId()
{
if (!Cache::has('role_id')) {
Cache::rememberForever('role_id', function () {
return $this->auth->user() !== null ? $this->user->getRoleId($this->auth->user()->id) : 0;
});
}
Cache::get('role_id');
}
示例9: register
/**
* Register the service provider.
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . self::PATH, 'haljson');
$this->app->singleton(\NilPortugues\Laravel5\HalJsonSerializer\HalJsonSerializer::class, function ($app) {
$mapping = $app['config']->get('haljson');
$key = \md5(\json_encode($mapping));
return Cache::rememberForever($key, function () use($mapping) {
return new HalJsonSerializer(new HalJsonTransformer(self::parseRoutes(new Mapper($mapping))));
});
});
}
开发者ID:jonphipps,项目名称:laravel5-hal-json-transformer,代码行数:14,代码来源:Laravel5HalJsonSerializerServiceProvider.php
示例10: register
/**
* Register the service provider.
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . self::PATH, 'jsonapi');
$this->app->singleton(JsonApiSerializer::class, function ($app) {
$mapping = $app['config']->get('jsonapi');
$key = md5(json_encode($mapping));
return Cache::rememberForever($key, function () use($mapping) {
return new JsonApiSerializer(new JsonApiTransformer(self::parseRoutes(new Mapper($mapping))));
});
});
}
示例11: selectCountryWithId
public function selectCountryWithId($app)
{
$app->form->macro('selectCountryWithId', function ($name, $selected = null, $options = []) use($app) {
$countries = Cache::rememberForever('brianfaust.countries.select.id.cca2', function () {
return Models\Country::get(['name', 'id'])->mapWithKeys(function ($item) {
return [$item['id'] => $item['name']['common']];
})->sort();
});
return $app->form->select($name, $countries, $selected, $options);
});
}
示例12: provider
public function provider()
{
return function ($app) {
if (config('app.debug')) {
$parsedRoutes = $this->parseRoutes(new Mapper($app['config']->get('jsonapi')));
} else {
$parsedRoutes = Cache::rememberForever('jsonapi.mapping', function () use($app) {
return $this->parseRoutes(new Mapper($app['config']->get('jsonapi')));
});
}
return new JsonApiSerializer(new JsonApiTransformer($parsedRoutes));
};
}
示例13: refreshLanguage
private function refreshLanguage()
{
$language = App::make(LanguageInterface::class);
$key = 'default_language';
Cache::forget($key);
Cache::rememberForever($key, function () use($language) {
return $language->whereDefault(1)->firstOrFail();
});
$key = 'active_languages';
Cache::forget($key);
Cache::rememberForever($key, function () use($language) {
return $language->whereActive(1)->get();
});
}
示例14: cache
/**
* Retrieve from cache if not empty, otherwise store results
* of query in cache
*
* @param string $key
* @param Builder $query
* @param string $verb Optional Builder verb to execute query
*
* @return Collection|Model|array|null
*/
protected function cache($key, Builder $query, $verb = 'get')
{
$actualKey = $this->indexKey($key);
$fetchData = function () use($actualKey, $query, $verb) {
$this->log('refreshing cache for ' . get_class($this) . ' (' . $actualKey . ')');
return $this->callQueryVerb($query, $verb);
};
if ($this->enableCaching) {
if ($this->cacheForMinutes > 0) {
return CacheFacade::remember($actualKey, $this->cacheForMinutes, $fetchData);
}
return CacheFacade::rememberForever($actualKey, $fetchData);
}
return $fetchData();
}
示例15: __construct
public function __construct()
{
$this->client = new \Google_Client();
$this->client->setClientId($this->ClientId);
$this->client->setClientSecret($this->ClientSecret);
$this->client->refreshToken($this->refreshToken);
$this->service = new \Google_Service_Drive($this->client);
// we cache the id to avoid having google creating
// a new folder on each time we call it,
// because google drive works with 'id' not 'name'
// & thats why u could have duplicated folders under the same name
Cache::rememberForever('folder_id', function () {
return $this->create_folder();
});
$this->folder_id = Cache::get('folder_id');
}