diff --git a/app/controllers/general.php b/app/controllers/general.php index 620f16f1c1..18f4825724 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -612,6 +612,7 @@ App::get('/.well-known/acme-challenge') }); include_once __DIR__ . '/shared/api.php'; +include_once __DIR__ . '/shared/cache.php'; include_once __DIR__ . '/shared/web.php'; foreach (Config::getParam('services', []) as $service) { diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index b22cd9d968..2bbe932b66 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -239,24 +239,6 @@ App::shutdown(function (App $utopia, Request $request, Response $response, Docum $route = $utopia->match($request); - $groups = $route->getGroups(); - if (in_array('cache', $groups)) { - if (!empty($cacheKey) && !empty($cachePath)) { - $cacheLog = $dbForProject->getDocument('cache', $cacheKey); - if ($cacheLog->isEmpty()) { - Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([ - '$id' => $cacheKey, - 'accessedAt' => time(), - 'path' => $cachePath - ]))); - } else { - $cacheLog->setAttribute('accessedAt', time()); - Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog)); - } - } - } - - if ( App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled' && $project->getId() diff --git a/app/controllers/shared/cache.php b/app/controllers/shared/cache.php new file mode 100644 index 0000000000..b371740df9 --- /dev/null +++ b/app/controllers/shared/cache.php @@ -0,0 +1,23 @@ +getDocument('cache', $cacheKey); + if ($cacheLog->isEmpty()) { + Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([ + '$id' => $cacheKey, + 'accessedAt' => time(), + 'path' => $cachePath + ]))); + } else { + $cacheLog->setAttribute('accessedAt', time()); + Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog)); + } + } +}, ['dbForProject', 'cacheKey', 'cachePath'], 'cache');