Skip to content

Commit e8d441c

Browse files
committed
docs: add docs
1 parent 4fc5c2b commit e8d441c

File tree

3 files changed

+88
-6
lines changed

3 files changed

+88
-6
lines changed

user_guide_src/source/changelogs/v4.4.0.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ Others
222222
- It can also take an object that implements ``ResponseInterface`` as its first argument.
223223
- It implements ``ResponsableInterface``.
224224
- **DebugBar:** Now :ref:`view-routes` are displayed in *DEFINED ROUTES* on the *Routes* tab.
225-
- **Factories:** You can now define the classname that will actually be loaded.
226-
See :ref:`factories-defining-classname-to-be-loaded`.
225+
- **Factories:**
226+
- You can now define the classname that will actually be loaded.
227+
See :ref:`factories-defining-classname-to-be-loaded`.
228+
- The Config Caching implemented. See :ref:`factories-config-caching` for details.
227229

228230
Message Changes
229231
***************

user_guide_src/source/concepts/factories.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

user_guide_src/source/installation/upgrade_440.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,16 @@ match the new array structure.
117117
Mandatory File Changes
118118
**********************
119119

120-
index.php
121-
=========
120+
index.php and spark
121+
===================
122122

123-
The following file received significant changes and
123+
The following files received significant changes and
124124
**you must merge the updated versions** with your application:
125125

126126
- ``public/index.php`` (see also :ref:`v440-codeigniter-and-exit`)
127+
- ``spark``
127128

128-
.. important:: If you don't update the above file, CodeIgniter will not work
129+
.. important:: If you don't update the above files, CodeIgniter will not work
129130
properly after running ``composer update``.
130131

131132
The upgrade procedure, for example, is as follows:
@@ -134,6 +135,7 @@ The following file received significant changes and
134135
135136
composer update
136137
cp vendor/codeigniter4/framework/public/index.php public/index.php
138+
cp vendor/codeigniter4/framework/spark spark
137139
138140
Config Files
139141
============

0 commit comments

Comments
 (0)