N°6618 - Router: Fix available routes cache being re-generated at each call

This commit is contained in:
Molkobain
2023-08-01 21:43:09 +02:00
parent df1cb0b6e3
commit a5c980113b
2 changed files with 66 additions and 3 deletions

View File

@@ -138,12 +138,15 @@ class Router
{
$aRoutes = [];
$bUseCache = false === utils::IsDevelopmentEnvironment();
$bMustWriteCache = false;
$sCacheFilePath = $this->GetCacheFileAbsPath();
// Try to read from cache
if ($bUseCache) {
if (is_file($sCacheFilePath)) {
$aRoutes = include $sCacheFilePath;
} else {
$bMustWriteCache = true;
}
}
@@ -180,11 +183,11 @@ class Router
}
}
// Save to cache
if ($bUseCache) {
// Save to cache if it doesn't exist already
if ($bMustWriteCache) {
$sCacheContent = "<?php\n\nreturn ".var_export($aRoutes, true).";";
SetupUtils::builddir(dirname($sCacheFilePath));
file_put_contents($sCacheFilePath, $sCacheContent);
file_put_contents($sCacheFilePath, $sCacheContent, LOCK_EX);
}
return $aRoutes;