Skip to content

Commit

Permalink
[TM-1586] set cache timeout for dashboard endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarLima1 committed Dec 30, 2024
1 parent cf5ea8e commit b564190
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunActiveCountriesTableJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function handle(RunActiveCountriesTableService $runActiveCountriesTableSe

Redis::set('dashboard:active-countries-table|' . $this->cacheParameter, json_encode([
'data' => $response,
]));
]), 'EX', config('cache.ttl.dashboard'));

$delayedJob->update([
'status' => DelayedJob::STATUS_SUCCEEDED,
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunActiveProjectsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunActiveProjectsService $runActiveProjectsService)
]
);
$response = $runActiveProjectsService->runActiveProjectsJob($request);
Redis::set('dashboard:active-projects|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:active-projects|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));


$delayedJob->update([
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunHectaresRestoredJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunHectaresRestoredService $runHectaresRestoredService)
]
);
$response = $runHectaresRestoredService->runHectaresRestoredJob($request);
Redis::set('dashboard:indicator/hectares-restoration' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:indicator/hectares-restoration' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));


$delayedJob->update([
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunJobsCreatedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function handle(JobsCreatedService $jobsCreatedService)
]);

$response = $jobsCreatedService->calculateJobsCreated($request);
Redis::set('dashboard:jobs-created|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:jobs-created|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));

$delayedJob->update([
'status' => DelayedJob::STATUS_SUCCEEDED,
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunTopTreesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunTopTreesService $runTopTreesService)
]
);
$response = $runTopTreesService->runTopTreesJob($request);
Redis::set('dashboard:top-trees-planted|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:top-trees-planted|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));


$delayedJob->update([
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunTotalHeaderJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunTotalHeaderService $runTotalHeaderService)
]
);
$response = $runTotalHeaderService->runTotalHeaderJob($request);
Redis::set('dashboard:total-section-header|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:total-section-header|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));

$delayedJob->update([
'status' => DelayedJob::STATUS_SUCCEEDED,
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunTreeRestorationGoalJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function handle(TreeRestorationGoalService $treeRestorationGoalService)
]);

$response = $treeRestorationGoalService->calculateTreeRestorationGoal($request);
Redis::set('dashboard:tree-restoration-goal|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:tree-restoration-goal|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));

$delayedJob->update([
'status' => DelayedJob::STATUS_SUCCEEDED,
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunVolunteersAverageJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunVolunteersAverageService $runVolunteersAverageService)
]
);
$response = $runVolunteersAverageService->runVolunteersAverageJob($request);
Redis::set('dashboard:volunteers-survival-rate|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:volunteers-survival-rate|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));


$delayedJob->update([
Expand Down
14 changes: 14 additions & 0 deletions config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,18 @@

'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),

/*
|--------------------------------------------------------------------------
| Cache Timeout Values
|--------------------------------------------------------------------------
|
| Here you may define the cache timeout values for different sections
| of the application. These values can be used in any controllers
| to set the time-to-live (TTL) for cached items.
|
*/

'ttl' => [
'dashboard' => 86400, // 24 hours
]
];

0 comments on commit b564190

Please sign in to comment.