Improve module loading

This commit is contained in:
2024-10-22 13:49:42 +05:00
parent 96a5430cac
commit a52a39f78a
2 changed files with 24 additions and 1 deletions

View File

@@ -49,6 +49,10 @@ function modules_path(string $path = ''): string
*/
function modules(bool $withDisabled = false): Collection
{
if (temp_cache()->has('modules')) {
return temp_cache('modules');
}
/** @var array<int, string> */
$modulesDir = File::directories(modules_path());
$modules = collect();
@@ -74,5 +78,19 @@ function modules(bool $withDisabled = false): Collection
}
}
temp_cache()->put('modules', $modules);
return $modules;
}
/**
* Temprory cache for single request
*/
function temp_cache(string $key = ''): mixed
{
$tempCache = cache()->driver('array');
return ($key !== '')
? $tempCache->get($key)
: cache()->driver('array');
}