From f79395cfae99eb21fbd89f2b4842769598652ce8 Mon Sep 17 00:00:00 2001 From: Rico van Zelst Date: Sun, 26 Nov 2023 16:20:06 +0100 Subject: [PATCH] cache time --- app/Http/Controllers/ChampionController.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ChampionController.php b/app/Http/Controllers/ChampionController.php index f681948..a5166a8 100644 --- a/app/Http/Controllers/ChampionController.php +++ b/app/Http/Controllers/ChampionController.php @@ -8,18 +8,22 @@ use App\Models\Champion; use App\Models\ChampionRoles; use Illuminate\Support\Facades\Cache; + class ChampionController extends Controller { + /** * Display a listing of the resource. */ public function index() { - $champions = Cache::remember('championsListAllCache', 60 * 60 * 8, function () { + $eightHoursInSeconds = 60 * 60 * 8; + + $champions = Cache::remember('championsListAllCache', $eightHoursInSeconds, function () { return Champion::orderBy('name')->get(); }); - $roles = Cache::remember('championsRolesCache', 60 * 60 * 8, function () { + $roles = Cache::remember('championsRolesCache', $eightHoursInSeconds, function () { return ChampionRoles::orderBy('champion_name')->get(); }); @@ -47,13 +51,16 @@ class ChampionController extends Controller */ public function show(Champion $champion) { - $champion = Cache::remember('championShowCache' . $champion->slug, 60 * 60 * 8, function () use ($champion) { + $eightHoursInSeconds = 60 * 60 * 8; + $dayInSeconds = 60 * 60 * 24; + + $champion = Cache::remember('championShowCache' . $champion->slug, $eightHoursInSeconds, function () use ($champion) { return $champion->load('skins', 'lanes'); }); $splashColor = Cache::remember( 'championSplashColorCache' . $champion->slug, - 60 * 60 * 24, + $dayInSeconds, function () use ($champion) { return getAverageColorFromImageUrl($champion->getChampionImageAttribute()); }