add container cache config

This commit is contained in:
sunxyw
2023-02-07 16:31:32 +08:00
parent e563ade103
commit e8b6b81dea
2 changed files with 27 additions and 0 deletions

View File

@@ -38,6 +38,21 @@ class ContainerHolder
);
$builder->useAutowiring(true);
$builder->useAttributes(true);
// 容器缓存
$enable_cache = config('container.cache.enable', false);
if (is_callable($enable_cache)) {
$enable_cache = $enable_cache();
}
if ($enable_cache) {
// 检查 APCu 扩展是否可用
if (!extension_loaded('apcu')) {
logger()->warning('APCu 扩展未加载,容器缓存将不可用');
} else {
$builder->enableDefinitionCache(config('container.cache.namespace', ''));
}
}
return $builder->build();
}
}