@@ -262,3 +262,81 @@ that single call will return a new or shared instance:
262262
263263.. literalinclude :: factories/007.php
264264 :lines: 2-
265+
266+ .. _factories-config-caching :
267+
268+ Config Caching
269+ **************
270+
271+ .. versionadded :: 4.4.0
272+
273+ To improve performance, the Config Caching has been implemented.
274+
275+ Prerequisite
276+ ============
277+
278+ .. important :: Using this feature when the prerequisites are not met will prevent
279+ CodeIgniter from operating properly. Do not use this feature in such cases.
280+
281+ - To use this feature, the properties of all Config objects instantiated in
282+ Factories must not be modified after instantiation. Put another way, the Config
283+ classes must be an immutable or readonly classes.
284+ - By default, every Config class that is cached must implement ``__set_state() ``
285+ method.
286+
287+ How It Works
288+ ============
289+
290+ - Save the all Config instances in Factories into a cache file before shutdown,
291+ if the state of the Config instances in Factories changes.
292+ - Restore cached Config instances before CodeIgniter initialization if a cache
293+ is available.
294+
295+ Simply put, all Config instances held by Factories are cached immediately prior
296+ to shutdown, and the cached instances are used permanently.
297+
298+ How to Update Config Values
299+ ===========================
300+
301+ Once cached, the cache is never expired. Changing a existing Config file
302+ (or changing Environment Variables for it) will not update the cache nor the Config
303+ values.
304+
305+ So if you want to update Config values, update Config files or Environment Variables
306+ for them, and you must manually delete the cache file.
307+
308+ You can use the ``spark cache:clear `` command:
309+
310+ .. code-block :: console
311+
312+ php spark cache:clear
313+
314+ Or simply delete the **writable/cache/FactoriesCache_config ** file.
315+
316+ How to Enable Config Caching
317+ ============================
318+
319+ Uncomment the following code in **public/index.php **::
320+
321+ --- a/public/index.php
322+ +++ b/public/index.php
323+ @@ -49,8 +49,8 @@ if (! defined('ENVIRONMENT')) {
324+ }
325+
326+ // Load Config Cache
327+ -// $factoriesCache = new \CodeIgniter\Cache\FactoriesCache();
328+ -// $factoriesCache->load('config');
329+ +$factoriesCache = new \CodeIgniter\Cache\FactoriesCache();
330+ +$factoriesCache->load('config');
331+ // ^^^ Uncomment these lines if you want to use Config Caching.
332+
333+ /*
334+ @@ -79,7 +79,7 @@ $app->setContext($context);
335+ $app->run();
336+
337+ // Save Config Cache
338+ -// $factoriesCache->save('config');
339+ +$factoriesCache->save('config');
340+ // ^^^ Uncomment this line if you want to use Config Caching.
341+
342+ // Exits the application, setting the exit code for CLI-based applications
0 commit comments