From 2d832f015960257b995f20b04247031226dba3ae Mon Sep 17 00:00:00 2001 From: cp6 Date: Wed, 2 Mar 2022 00:42:50 +1100 Subject: [PATCH] Added cache for all servers Added cache for all servers --- app/Http/Controllers/ServerController.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 0901dad..5c2df1c 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -23,12 +23,16 @@ class ServerController extends Controller public function index() { - $servers = DB::table('servers as s') - ->join('pricings as pr', 's.id', '=', 'pr.service_id') - ->join('providers as p', 's.provider_id', '=', 'p.id') - ->join('locations as l', 's.location_id', '=', 'l.id') - ->join('os as o', 's.os_id', '=', 'o.id') - ->get(['s.*', 'pr.currency', 'pr.price', 'pr.term', 'pr.as_usd', 'pr.next_due_date', 'p.name as provider_name', 'l.name as location', 'o.name as os_name']); + $servers = Cache::remember('all_servers', 1440, function () { + return DB::table('servers as s') + ->join('pricings as pr', 's.id', '=', 'pr.service_id') + ->join('providers as p', 's.provider_id', '=', 'p.id') + ->join('locations as l', 's.location_id', '=', 'l.id') + ->join('os as o', 's.os_id', '=', 'o.id') + ->get(['s.*', 'pr.currency', 'pr.price', 'pr.term', 'pr.as_usd', 'pr.next_due_date', 'p.name as provider_name', 'l.name as location', 'o.name as os_name']); + + }); + return view('servers.index', compact(['servers'])); } @@ -165,6 +169,7 @@ class ServerController extends Controller Cache::forget('services_count');//Main page services_count cache Cache::forget('due_soon');//Main page due_soon cache Cache::forget('recently_added');//Main page recently_added cache + Cache::forget('all_servers');//all servers cache return redirect()->route('servers.index') ->with('success', 'Server Created Successfully.'); @@ -304,6 +309,7 @@ class ServerController extends Controller Cache::forget('services_count');//Main page services_count cache Cache::forget('due_soon');//Main page due_soon cache Cache::forget('recently_added');//Main page recently_added cache + Cache::forget('all_servers');//all servers cache return redirect()->route('servers.index') ->with('success', 'Server Updated Successfully.'); @@ -325,6 +331,7 @@ class ServerController extends Controller Cache::forget('services_count');//Main page services_count cache Cache::forget('due_soon');//Main page due_soon cache Cache::forget('recently_added');//Main page recently_added cache + Cache::forget('all_servers');//all servers cache return redirect()->route('servers.index') ->with('success', 'Server was deleted Successfully.');