/** * 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)); }
/** * 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; }); }
/** * @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(); }); }
/** * 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; }
/** * 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]; }); }
/** * 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); }
/** * 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); }); }
/** * 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(); }); }
/** * 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); }
/** * 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; }
/** * 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; }
/** * Get all published navigation. * * @return \Illuminate\Database\Eloquent\Collection|static[] */ public function getPublished() { return $this->cache->rememberForever('navigation.published', function () { return $this->repository->getPublished(); }); }
/** * 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); }
/** * 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(); }); }
/** * 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(); }); }
/** * Add site asset. * * @param string $type * @return \Roumen\Asset\Asset; */ public function addAsset($type) { return $this->cache->rememberForever('fileAssets.addAsset.' . $type, function () use($type) { return $this->repository->addAsset($type); }); }
/** * Retreive Permissions. * * @return \Illuminate\Database\Eloquent\Collection */ protected function getPermissions() { return $this->cache->rememberForever('permissions', function () { return $this->permissionRepository->all(); }); }
/** * Get an item from the cache, or store the default value forever. * * @param string $key * @param \Closure $callback * @return mixed */ public function rememberForever($key, Closure $callback) { return $this->cache->rememberForever($key, $callback); }
/** * Get all registered widgets. * * @return \Illuminate\Support\Collection */ public function allWidgets() { return $this->cache->rememberForever('extensions.widgets', function () { return $this->repository->allWidgets(); }); }