Skip to content

Commit

Permalink
add config for cache duration
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Sep 12, 2024
1 parent 465a699 commit 8b5ce12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions config/zeus-bolt.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,15 @@
'show_presets' => false,

'allow_design' => false,

/**
* since `collections` have many types, we cannot lazy load them
* but we cache them for a while to get better performance
* the key is: dataSource_*_response_md5
*
* here you can set the duration of the cache
*/
'cache' => [
'collection_values' => 30, // on seconds
],
];
2 changes: 1 addition & 1 deletion src/Fields/FieldsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function getCollectionsValuesForResponse(Field $field, FieldResponse $res
$dataSource = (int) $field->options['dataSource'] ?? $field->options['dataSource'];
$cacheKey = 'dataSource_' . $dataSource . '_response_' . md5(serialize($response));

$response = Cache::remember($cacheKey, 30 , function () use ($field, $response, $dataSource) {
$response = Cache::remember($cacheKey, config('zeus-bolt.cache.collection_values') , function () use ($field, $response, $dataSource) {

// Handle case when dataSource is not zero (new structure)
if ($dataSource !== 0) {
Expand Down

0 comments on commit 8b5ce12

Please sign in to comment.