Skip to content

Commit b1da40f

Browse files
committed
Add caching.
1 parent cfb4926 commit b1da40f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

laravel/src/SyncApiConstant.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Facades\Route;
66
use Illuminate\Support\Str;
7+
use Illuminate\Support\Facades\Cache;
78

89
/**
910
* Represents a constant within a sync API. Create instances using
@@ -99,10 +100,16 @@ public function hashData(array $data): string
99100

100101
public function generateConstantRoutes(): void
101102
{
103+
$kebabCasedName = $this->generateKebabCasedName();
104+
102105
Route::get(
103-
$this->generateKebabCasedName(),
104-
function () {
105-
$data = ($this->valueFactory)();
106+
$kebabCasedName,
107+
function () use ($kebabCasedName) {
108+
$data = Cache::remember(
109+
'sync_api_constant_' . $kebabCasedName,
110+
3600,
111+
$this->valueFactory
112+
);
106113

107114
return [
108115
'version' => $this->hashData($data),

0 commit comments

Comments
 (0)