Added caching (adjust setting in .env accordingly; CACHE_STORE=file)
parent
5a2cc96a95
commit
466d3168c4
|
@ -38,7 +38,7 @@ BROADCAST_CONNECTION=log
|
|||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=database
|
||||
|
||||
CACHE_STORE=database
|
||||
CACHE_STORE=file
|
||||
CACHE_PREFIX=
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class Api
|
||||
|
@ -16,10 +17,17 @@ class Api
|
|||
|
||||
$endpoint = env('FASTAPI_URI');
|
||||
$request = $endpoint.$path;
|
||||
|
||||
if (Cache::has($request)) {
|
||||
return Cache::get($request);
|
||||
}
|
||||
|
||||
$get = Http::get($request);
|
||||
|
||||
if($get->successful()){
|
||||
return $get->json();
|
||||
$result = $get->json();
|
||||
Cache::put($request, $result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue