Skip to content

Commit fef194b

Browse files
committed
perf: add config Optimize and move $configCacheEnabled
The Cache Config class that extends BaseConfig is very slow to instantiate.. See #8558 (comment)
1 parent eba1e9e commit fef194b

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

app/Config/Cache.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,4 @@ class Cache extends BaseConfig
168168
* @var bool|list<string>
169169
*/
170170
public $cacheQueryString = false;
171-
172-
/**
173-
* --------------------------------------------------------------------------
174-
* Config Caching
175-
* --------------------------------------------------------------------------
176-
*
177-
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
178-
*/
179-
public bool $configCacheEnabled = false;
180171
}

app/Config/Optimize.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Config;
4+
5+
/**
6+
* Optimization Configuration.
7+
*
8+
* NOTE: This class does not extend BaseConfig for performance reasons.
9+
* So you cannot replace the property values with Environment Variables.
10+
*
11+
* @immutable
12+
*/
13+
class Optimize
14+
{
15+
/**
16+
* --------------------------------------------------------------------------
17+
* Config Caching
18+
* --------------------------------------------------------------------------
19+
*
20+
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
21+
*/
22+
public bool $configCacheEnabled = false;
23+
}

system/Boot.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use CodeIgniter\CLI\Console;
1818
use CodeIgniter\Config\DotEnv;
1919
use Config\Autoload;
20-
use Config\Cache;
2120
use Config\Modules;
21+
use Config\Optimize;
2222
use Config\Paths;
2323
use Config\Services;
2424

@@ -55,7 +55,8 @@ public static function bootWeb(Paths $paths): int
5555
static::setExceptionHandler();
5656
static::initializeKint();
5757

58-
$configCacheEnabled = (new Cache())->configCacheEnabled ?? false;
58+
$configCacheEnabled = class_exists(Optimize::class)
59+
&& (new Optimize())->configCacheEnabled;
5960
if ($configCacheEnabled) {
6061
$factoriesCache = static::loadConfigCache();
6162
}

user_guide_src/source/concepts/factories.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ How to Enable Config Caching
318318

319319
.. versionadded:: 4.5.0
320320

321-
Set the following property to ``true`` in **app/Config/Cache.php**::
321+
Set the following property to ``true`` in **app/Config/Optimize.php**::
322322

323323
public bool $configCacheEnabled = true;
324324

0 commit comments

Comments
 (0)