ContainerDefinitionFetcher: cache the containers.json in apcu (#7951)

This commit is contained in:
Simon L.
2026-04-20 14:09:04 +02:00
committed by GitHub
2 changed files with 11 additions and 1 deletions

View File

@@ -53,6 +53,9 @@ RUN set -ex; \
build-base; \
pecl install APCu-5.1.28; \
docker-php-ext-enable apcu; \
{ \
echo 'apc.shm_size=32M'; \
} >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini; \
docker-php-ext-enable opcache; \
{ \
echo 'opcache.enable=1'; \

View File

@@ -39,7 +39,14 @@ readonly class ContainerDefinitionFetcher {
*/
private function GetDefinition(): array
{
$data = json_decode((string)file_get_contents(DataConst::GetContainersDefinitionPath()), true, 512, JSON_THROW_ON_ERROR);
$containersDefinitionPath = DataConst::GetContainersDefinitionPath();
$cacheKey = 'containers-json-' . $containersDefinitionPath;
$cachedJson = apcu_fetch($cacheKey);
if (!is_string($cachedJson)) {
$cachedJson = (string)file_get_contents($containersDefinitionPath);
apcu_add($cacheKey, $cachedJson);
}
$data = json_decode($cachedJson, true, 512, JSON_THROW_ON_ERROR);
// We store this information for later because we need to use it to distinct between community containers and default containers.
$standardContainerNames = array_column($data['aio_services_v1'], 'container_name');