diff options
| author | horus | 2022-01-07 20:07:28 +0100 |
|---|---|---|
| committer | horus | 2022-01-07 20:07:28 +0100 |
| commit | a8c4aad640b3586ba93c9a7cfac052b69d2fbba4 (patch) | |
| tree | dbe8440606983fff37e9fc18554ea06b50fdbb11 /app/Http/Controllers | |
| parent | b5eaf86c92f0d00051ce7efa4f1737132bb4d7e2 (diff) | |
| download | kategorischeraperitif-a8c4aad640b3586ba93c9a7cfac052b69d2fbba4.tar.gz | |
caching
Diffstat (limited to 'app/Http/Controllers')
| -rw-r--r-- | app/Http/Controllers/CocktailController.php | 11 | ||||
| -rw-r--r-- | app/Http/Controllers/IndexController.php | 48 |
2 files changed, 45 insertions, 14 deletions
diff --git a/app/Http/Controllers/CocktailController.php b/app/Http/Controllers/CocktailController.php index f876dfe..21655d2 100644 --- a/app/Http/Controllers/CocktailController.php +++ b/app/Http/Controllers/CocktailController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Cache; + use App\Cocktail; use App\Ingredient; use App\Libraries\Helper; @@ -13,8 +15,13 @@ class CocktailController extends Controller public function index() { - $cocktails = new Cocktail; - $cocktail_count = $cocktails->count(); + if ( Cache::has('cocktail_count') ) { + $cocktail_count= Cache::get('cocktail_count'); + } else { + $cocktails = new Cocktail; + $cocktail_count = $cocktails->count(); + Cache::put('cocktail_count', $cocktail_count, 6000); // 100 minutes + } return view('cocktail_index', [ "cocktail_count" => $cocktail_count ]); } diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 24c5615..c53fc2a 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -19,31 +19,55 @@ class IndexController extends Controller { * @return Response */ public function angebote(Request $request) { - + + $views = array("whisky", "wodka", "gin", "rum", "misc"); + $cache_angebote = ""; + if ( Cache::has('angebote_index') ) { - return Cache::get('angebote_index'); + $data = Cache::get('angebote_index'); } else { - $views = array("whisky", "wodka", "gin", "rum", "misc"); $data = $this->getAngeboteData($request); + Cache::put('angebote_index', $data , 6000); // 100 minutes + } + if ( Cache::has('angebote_count') ) { + $count = Cache::get('angebote_count'); + } else { $count = DB::select("SELECT count(*) as count FROM all_view")[0]; + Cache::put('angebote_count', $count, 6000); // 100 minutes + } - $cached_data = view('angebote_index', ['data' => $data, 'views' => $views, 'hits' => $count])->render(); - - Cache::put('angebote_index', $cached_data, 6000); // 100 minutes + #$count = DB::select("SELECT count(*) as count FROM all_view")[0]; - return $cached_data; - } + $cache_angebote = view('fragments.angebote', ['data' => $data, 'views' => $views, 'hits' => $count])->render(); + return view('angebote_index', ['data' => $data, 'views' => $views, 'hits' => $count, 'cache_angebote' => $cache_angebote])->render(); } public function index(Request $request) { $views = array("whisky", "wodka", "gin", "rum", "misc"); - $data = $this->getAngeboteData($request); - $count = DB::select("SELECT count(*) as count FROM all_view")[0]; - $cocktails = new Cocktail; - $cocktail_count = $cocktails->count(); + if ( Cache::has('angebote_index') ) { + $data = Cache::get('angebote_index'); + } else { + + $data = $this->getAngeboteData($request); + + Cache::put('angebote_index', $data , 6000); // 100 minutes + } + if ( Cache::has('angebote_count') ) { + $count= Cache::get('angebote_count'); + } else { + $count = DB::select("SELECT count(*) as count FROM all_view")[0]; + Cache::put('angebote_count', $count, 6000); // 100 minutes + } + if ( Cache::has('cocktail_count') ) { + $cocktail_count= Cache::get('cocktail_count'); + } else { + $cocktails = new Cocktail; + $cocktail_count = $cocktails->count(); + Cache::put('cocktail_count', $cocktail_count, 6000); // 100 minutes + } return view('index', ['data' => $data, 'views' => $views, 'hits' => $count, 'cocktail_count' => $cocktail_count])->render(); } |
