本文整理汇总了PHP中Illuminate\Contracts\Cache\Repository::rememberForever方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::rememberForever方法的具体用法?PHP Repository::rememberForever怎么用?PHP Repository::rememberForever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Contracts\Cache\Repository
的用法示例。
在下文中一共展示了Repository::rememberForever方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cache
/**
* Cache a view. If minutes are null, the view is cached forever.
*
* @param array $data
* @param string $view
* @param array $mergeData
* @param int $minutes
* @param string $key
* @param string|array $tag
*
* @return string
*/
public function cache($data, $view, $mergeData = null, $minutes = null, $key = null, $tag = null)
{
if (!$this->enabled) {
return call_user_func($this->renderView($view, $data, $mergeData));
}
$viewKey = $this->getCacheKeyForView($view, $key);
$mergeData = $mergeData ?: [];
$tags = [$this->cacheKey];
if ($tag) {
if (!is_array($tag)) {
$tag = [$tag];
}
$tags = array_merge($tags, $tag);
}
if ($this->cacheIsTaggable && $minutes === null) {
return $this->cache->tags($tags)->rememberForever($viewKey, $this->renderView($view, $data, $mergeData));
}
if ($this->cacheIsTaggable) {
return $this->cache->tags($tags)->remember($viewKey, $minutes, $this->renderView($view, $data, $mergeData));
}
if ($minutes === null) {
return $this->cache->rememberForever($viewKey, $this->renderView($view, $data, $mergeData));
}
return $this->cache->remember($viewKey, $minutes, $this->renderView($view, $data, $mergeData));
}
示例2: put
/**
* Put to the cache.
*
* @param mixed $key
* @param string $fragment
*/
public function put($key, $fragment)
{
$key = $this->normalizeCacheKey($key);
return $this->cache->rememberForever($key, function () use($fragment) {
return $fragment;
});
}
示例3: roles
/**
* @param bool $forget
*
* @return \Illuminate\Database\Eloquent\Collection|Role[]|null
*/
public function roles(bool $forget = false)
{
if ($forget === true) {
return $this->cache->forget(self::ROLE_KEY);
}
return $this->cache->rememberForever(self::ROLE_KEY, function () {
return app(Role::class)->with('permissions')->get();
});
}
示例4: all
/**
* Get the dataset collection
*
* @return \Illuminate\Support\Collection
*/
public function all()
{
$cacheKey = 'dataset' . (new ReflectionClass($this))->getShortName();
if ($this->cache->has($cacheKey)) {
return $this->cache->get($cacheKey);
}
$dataset = $this->cache->rememberForever($cacheKey, function () {
return $this->getDataset();
});
return $dataset;
}
示例5: getComponent
/**
* Get a TextFormatter component.
*
* @param string $name "renderer" or "parser"
* @return mixed
*/
protected function getComponent($name)
{
$cacheKey = 'flarum.formatter.' . $name;
return $this->cache->rememberForever($cacheKey, function () use($name) {
return $this->getConfigurator()->finalize()[$name];
});
}
示例6: remember
/**
* Get an item from the cache, or store the default value forever.
*
* @param string $key
* @param \Closure $callback
* @return mixed
*/
protected function remember($key, Closure $callback)
{
if (app()->environment('local')) {
return $callback();
}
return $this->cache->rememberForever($key, $callback);
}
示例7: loadContent
/**
* Load content.
*
* @param string $file
*
* @return mixed
*/
protected function loadContent($file)
{
return $this->cache->rememberForever("doc.{$file}", function () use($file) {
$this->validateFileDoesExist($file);
return $this->files->get($file);
});
}
示例8: __construct
/**
* Initialize the Option Class
* build the Config array.
*
* @param StorageContract $storage The Database Interface
* @param CacheContract $cache Laravel CacheContract
*/
public function __construct(StorageContract $storage, ConfigContract $config, CacheContract $cache)
{
$this->storage = $storage;
$this->cache = $cache;
$this->config = $config;
$this->items = $cache->rememberForever('weboap.options', function () {
return $this->storage->all();
});
}
示例9: getCached
/**
* Pull the settings from the cache repository or query for it.
*
* @return array
*/
protected function getCached()
{
$this->grabbedCache = true;
$cached = $this->cache->rememberForever('settings', function () {
try {
return $this->setting->oldest('name')->pluck('value', 'name')->all();
} catch (\PDOException $e) {
return [];
}
});
return $this->settings = array_merge($this->settings, $cached);
}
示例10: get
/**
* Get the specified setting value.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
$this->fire('getting', $key, [$key, $default]);
$generatedKey = $this->getKey($key);
if ($this->isCacheEnabled()) {
$repository = $this->repository;
$value = $this->cache->rememberForever($generatedKey, function () use($repository, $generatedKey) {
return $repository->get($generatedKey);
});
} else {
$value = $this->repository->get($generatedKey, $default);
}
if (!is_null($value)) {
$value = $this->unserializeValue($this->isEncryptionEnabled() ? $this->encrypter->decrypt($value) : $value);
} else {
$value = $default;
}
$this->fire('get', $key, [$key, $value, $default]);
$this->context(null);
return $value;
}
示例11: render
/**
* Render the document.
*
* This will run all document:render hooks and then return the
* output. Should be called within a view.
*
* @return string
*/
public function render()
{
if ($this->rendered) {
return $this->content;
}
// todo implement this. if changes are made that influence the attributes (ex, the project config), the cache should drop.
// this is a example of how to create a unique hash for it. not sure if it would work out
// $attributesChanged = md5(collect(array_dot($this->attributes))->values()->transform(function ($val) {
// return md5((string)$val);
// })->implode('.'));
$this->codex->dev->benchmark('document');
$this->hookPoint('document:render');
if ($this->shouldCache()) {
$minutes = $this->getCodex()->config('document.cache.minutes', null);
if ($minutes === null) {
$lastModified = (int) $this->cache->rememberForever($this->getCacheKey(':last_modified'), function () {
return 0;
});
} else {
$lastModified = (int) $this->cache->remember($this->getCacheKey(':last_modified'), $minutes, function () {
return 0;
});
}
if ($this->lastModified !== $lastModified || $this->cache->has($this->getCacheKey()) === false) {
$this->runProcessors();
$this->cache->put($this->getCacheKey(':last_modified'), $this->lastModified, $minutes);
$this->cache->put($this->getCacheKey(':content'), $this->content, $minutes);
} else {
$this->content = $this->cache->get($this->getCacheKey(':content'));
}
} else {
$this->runProcessors();
}
$this->rendered = true;
$this->hookPoint('document:rendered');
$this->codex->dev->addMessage($this->toArray());
$this->codex->dev->stopBenchmark(true);
return $this->content;
}
示例12: getPublished
/**
* Get all published navigation.
*
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function getPublished()
{
return $this->cache->rememberForever('navigation.published', function () {
return $this->repository->getPublished();
});
}
示例13: cacheRememberForever
/**
* Remember the result value for a closure forever
* @param $key
* @param $callback
*
* @return mixed
*/
public function cacheRememberForever($key, $callback)
{
return $this->cache->rememberForever($this->cachePrefix($key), $callback);
}
示例14: all
/**
* Get all the setting entries.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function all()
{
return !$this->isCached() ? $this->model->all() : $this->cache->rememberForever($this->getCacheKey(), function () {
return $this->model->all();
});
}
示例15: getPermissions
/**
* Get the current permissions.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
protected function getPermissions()
{
return $this->cache->rememberForever($this->cacheKey, function () {
return app(Permission::class)->with('roles')->get();
});
}