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