mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
feat: Add caching to streamer data retrieval
- Added caching mechanism to store and retrieve streamer data for API responses, improving performance. - Implemented cache forget method in StreamerPanelController for CRUD operations to update cached data accordingly.
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Models\Streamer;
|
use App\Models\Streamer;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
|
||||||
class StreamerController extends Controller
|
class StreamerController extends Controller
|
||||||
{
|
{
|
||||||
@@ -22,4 +24,15 @@ class StreamerController extends Controller
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API: JSON response of all streamers.
|
||||||
|
* Data is cached for 12 hours.
|
||||||
|
*/
|
||||||
|
public function all()
|
||||||
|
{
|
||||||
|
$streamers = Cache::remember('streamersListAllAPICache', 60 * 60 * 12, static fn () => Streamer::orderBy('champion_id')->get());
|
||||||
|
|
||||||
|
return response()->json($streamers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||||||
use App\Models\Streamer;
|
use App\Models\Streamer;
|
||||||
use App\Models\Champion;
|
use App\Models\Champion;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
class StreamerPanelController extends Controller
|
class StreamerPanelController extends Controller
|
||||||
{
|
{
|
||||||
@@ -41,6 +42,8 @@ class StreamerPanelController extends Controller
|
|||||||
|
|
||||||
Streamer::create($request->all());
|
Streamer::create($request->all());
|
||||||
|
|
||||||
|
Cache::forget('streamersListAllAPICache');
|
||||||
|
|
||||||
return redirect()->route('streamerpanel.index');
|
return redirect()->route('streamerpanel.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +72,8 @@ class StreamerPanelController extends Controller
|
|||||||
|
|
||||||
$streamer->update($request->all());
|
$streamer->update($request->all());
|
||||||
|
|
||||||
|
Cache::forget('streamersListAllAPICache');
|
||||||
|
|
||||||
return redirect()->route('streamerpanel.index');
|
return redirect()->route('streamerpanel.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +84,8 @@ class StreamerPanelController extends Controller
|
|||||||
{
|
{
|
||||||
$streamer->delete();
|
$streamer->delete();
|
||||||
|
|
||||||
|
Cache::forget('streamersListAllAPICache');
|
||||||
|
|
||||||
return redirect()->route('streamerpanel.index');
|
return redirect()->route('streamerpanel.index');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
use App\Http\Controllers\StreamerController;
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| API Routes
|
Route::get('/streamers', [StreamerController::class, 'all']);
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Here is where you can register API routes for your application. These
|
|
||||||
| routes are loaded by the RouteServiceProvider and all of them will
|
|
||||||
| be assigned to the "api" middleware group. Make something great!
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user