From 15fb21b79b87d30262cf6dafca3aa385995f3545 Mon Sep 17 00:00:00 2001 From: Alexandr Chernyaev Date: Sun, 12 Jan 2025 02:17:53 +0300 Subject: [PATCH] Changed cache to `flexible` --- app/Docs.php | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/app/Docs.php b/app/Docs.php index ab636114..f874b3aa 100644 --- a/app/Docs.php +++ b/app/Docs.php @@ -150,11 +150,14 @@ public function content(): ?string */ public function view(string $view) { - $data = Cache::remember('doc-file-view-data'.$this->path, now()->addMinutes(30), fn () => collect()->merge($this->variables())->merge([ - 'docs' => $this, - 'content' => $this->content(), - 'edit' => $this->getEditUrl(), - ])); + $data = Cache::flexible( + 'doc-file-view-data'.$this->path, + [now()->addMinutes(30), now()->addHours(2)], + fn () => collect()->merge($this->variables())->merge([ + 'docs' => $this, + 'content' => $this->content(), + 'edit' => $this->getEditUrl(), + ])); return view($view, $data); } @@ -166,18 +169,21 @@ public function view(string $view) */ public function getMenu(): array { - return Cache::remember('doc-navigation-'.$this->version, now()->addHours(2), function () { - $page = Storage::disk('docs')->get($this->version.'/documentation.md'); - - $html = Str::of($page) - ->after('---') - ->after('---') - ->replace('{{version}}', $this->version) - ->markdown() - ->toString(); - - return $this->docsToArray($html); - }); + return Cache::flexible( + 'doc-navigation-'.$this->version, + [now()->addMinutes(30), now()->addHours(2)], + function () { + $page = Storage::disk('docs')->get($this->version.'/documentation.md'); + + $html = Str::of($page) + ->after('---') + ->after('---') + ->replace('{{version}}', $this->version) + ->markdown() + ->toString(); + + return $this->docsToArray($html); + }); } /** @@ -300,8 +306,9 @@ private function fetchGitHubDiff(?string $key = null): Collection { $hash = sha1($this->content()); - return Cache::remember("docs-diff-$this->version-$this->file-$hash", - now()->addHours(2), + return Cache::flexible( + "docs-diff-$this->version-$this->file-$hash", + [now()->addMinutes(30), now()->addHours(2)], fn () => Http::withBasicAuth('token', config('services.github.token')) ->get("https://api.github.com/repos/laravel/docs/commits?sha={$this->version}&path={$this->file}") ->collect($key)