From d6326758a8cabca9ab96e6b5b4ffe5c61c58ec51 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 30 Jun 2025 20:58:00 +0400 Subject: [PATCH 1/2] patch: increase cache ttl to ensure hits --- app/controllers/shared/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 735487339f..58b0f9a8a9 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -564,7 +564,7 @@ App::init() $cache = new Cache( new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()) ); - $timestamp = 60 * 60 * 24 * 30; + $timestamp = 60 * 60 * 24 * 180; // Temporarily increase the TTL to 180 day to ensure files in the cache are still fetched. $data = $cache->load($key, $timestamp); if (!empty($data) && !$cacheLog->isEmpty()) { From fd7628efe84308b6c04b17cb6fa2f48854f32149 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 30 Jun 2025 21:03:30 +0400 Subject: [PATCH 2/2] refactor: streamline cache handling in App::shutdown() and ensure file modification time updates --- app/controllers/shared/api.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 58b0f9a8a9..76fe177b0b 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -564,7 +564,7 @@ App::init() $cache = new Cache( new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()) ); - $timestamp = 60 * 60 * 24 * 180; // Temporarily increase the TTL to 180 day to ensure files in the cache are still fetched. + $timestamp = 60 * 60 * 24 * 180; // Temporarily increase the TTL to 180 day to ensure files in the cache are still fetched. $data = $cache->load($key, $timestamp); if (!empty($data) && !$cacheLog->isEmpty()) { @@ -831,6 +831,10 @@ App::shutdown() $resourceType = $parseLabel($pattern, $responsePayload, $requestParams, $user); } + $cache = new Cache( + new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()) + ); + $key = $request->cacheIdentifier(); $signature = md5($data['payload']); $cacheLog = Authorization::skip(fn () => $dbForProject->getDocument('cache', $key)); @@ -848,12 +852,11 @@ App::shutdown() } elseif (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_CACHE_UPDATE)) > $accessedAt) { $cacheLog->setAttribute('accessedAt', $now); Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog)); + // Overwrite the file every APP_CACHE_UPDATE seconds to update the file modified time that is used in the TTL checks in cache->load() + $cache->save($key, $data['payload']); } if ($signature !== $cacheLog->getAttribute('signature')) { - $cache = new Cache( - new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()) - ); $cache->save($key, $data['payload']); } }