Skip to content

Commit

Permalink
Changed cache to flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Jan 11, 2025
1 parent 5dfc06a commit 15fb21b
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions app/Docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
});
}

/**
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 15fb21b

Please sign in to comment.