From a2416590e8a2c2c8151920d45f0d1e764876eb12 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 29 Feb 2024 09:04:23 +0900 Subject: [PATCH] perf: add config Optimize and move $configCacheEnabled The Cache Config class that extends BaseConfig is very slow to instantiate.. See https://github.com/codeigniter4/CodeIgniter4/pull/8558#discussion_r1506813270 --- app/Config/Cache.php | 9 -------- app/Config/Optimize.php | 23 ++++++++++++++++++++ system/Boot.php | 5 +++-- user_guide_src/source/concepts/factories.rst | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 app/Config/Optimize.php diff --git a/app/Config/Cache.php b/app/Config/Cache.php index 6c61b0de1b56..3fbade6840cc 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -168,13 +168,4 @@ class Cache extends BaseConfig * @var bool|list */ public $cacheQueryString = false; - - /** - * -------------------------------------------------------------------------- - * Config Caching - * -------------------------------------------------------------------------- - * - * @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching - */ - public bool $configCacheEnabled = false; } diff --git a/app/Config/Optimize.php b/app/Config/Optimize.php new file mode 100644 index 000000000000..7895f16b3093 --- /dev/null +++ b/app/Config/Optimize.php @@ -0,0 +1,23 @@ +configCacheEnabled ?? false; + $configCacheEnabled = class_exists(Optimize::class) + && (new Optimize())->configCacheEnabled; if ($configCacheEnabled) { $factoriesCache = static::loadConfigCache(); } diff --git a/user_guide_src/source/concepts/factories.rst b/user_guide_src/source/concepts/factories.rst index 7d7133afcf1f..094e2a9d0b41 100644 --- a/user_guide_src/source/concepts/factories.rst +++ b/user_guide_src/source/concepts/factories.rst @@ -318,7 +318,7 @@ How to Enable Config Caching .. versionadded:: 4.5.0 -Set the following property to ``true`` in **app/Config/Cache.php**:: +Set the following property to ``true`` in **app/Config/Optimize.php**:: public bool $configCacheEnabled = true;