Add clear cache via Request
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
14b6e22b49
commit
712fb479dc
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
|
||||
use Silva\Adrema\Support\ClearCache;
|
||||
use Silva\Adrema\Support\Proxy;
|
||||
|
||||
Route::get('/adrema-api/{route}', fn (string $route) => Response::json(app(Proxy::class)->run($route, 'get')))
|
||||
->where('route', '[a-zA-Z0-9\-/]+')->middleware('api');
|
||||
Route::post('/adrema-api/{route}', fn (string $route) => app(Proxy::class)->submit($route))
|
||||
->where('route', '[a-zA-Z0-9\-/]+')->middleware('api');
|
||||
|
||||
Route::get('/adrema/clear-cache', fn () => app(ClearCache::class)->run());
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Silva\Adrema\Support;
|
||||
|
||||
use Cache;
|
||||
|
||||
class ClearCache
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
Cache::forget('adrema-all-events');
|
||||
}
|
||||
}
|
|
@ -3,19 +3,17 @@
|
|||
namespace Silva\Adrema\Support;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Cache;
|
||||
|
||||
class FetchAllEvents
|
||||
{
|
||||
public function run(): ?Collection
|
||||
{
|
||||
$events = Cache::remember('adrema-all-events', 3600, function () {
|
||||
return app(Proxy::class)->run('/api/form');
|
||||
});
|
||||
$events = app(Proxy::class)->run('api/form');
|
||||
|
||||
if (!$events) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return collect($events);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Silva\Adrema\Support;
|
||||
|
||||
use Cache;
|
||||
use Silva\Adrema\Models\Settings;
|
||||
use Http;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
@ -9,6 +10,15 @@ use Illuminate\Http\JsonResponse;
|
|||
class Proxy
|
||||
{
|
||||
public function run(string $url): ?array
|
||||
{
|
||||
if ($url === 'api/form') {
|
||||
return Cache::rememberForever('adrema-all-events', fn () => $this->get($url));
|
||||
}
|
||||
|
||||
return $this->get($url);
|
||||
}
|
||||
|
||||
protected function get(string $url): ?array
|
||||
{
|
||||
$response = Http::acceptJson()->get($this->url($url));
|
||||
|
||||
|
|
Loading…
Reference in New Issue