You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/configuration.md
+44-7Lines changed: 44 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,11 @@ Example:
26
26
public $handlers = ['database'];
27
27
```
28
28
29
+
### Deferred writes
30
+
31
+
Handlers like `database` and `file` support deferred writes. When `deferWrites` is enabled, multiple `set()` and `forget()` calls
32
+
are batched into the minimum number of database calls or file writes. The actual changes happen during the `post_system` event.
33
+
29
34
### Multiple handlers
30
35
31
36
Example:
@@ -44,6 +49,8 @@ This configuration will:
44
49
45
50
Only handlers marked as `writeable => true` will be used when calling `set()`, `forget()`, or `flush()` methods.
46
51
52
+
---
53
+
47
54
## DatabaseHandler
48
55
49
56
This handler stores settings in a database table and is production-ready for high-traffic applications.
@@ -54,21 +61,36 @@ This handler stores settings in a database table and is production-ready for hig
54
61
*`table` - The database table name for storing settings. Default: `'settings'`
55
62
*`group` - The database connection group to use. Default: `null` (uses default connection)
56
63
*`writeable` - Whether this handler supports write operations. Default: `true`
64
+
*`deferWrites` - Whether to defer writes until the end of request (`post_system` event). Default: `false`
57
65
58
66
Example:
59
67
60
68
```php
61
69
public $database = [
62
-
'class' => DatabaseHandler::class,
63
-
'table' => 'settings',
64
-
'group' => null,
65
-
'writeable' => true,
70
+
'class' => DatabaseHandler::class,
71
+
'table' => 'settings',
72
+
'group' => null,
73
+
'writeable' => true,
74
+
'deferWrites' => false,
66
75
];
67
76
```
68
77
69
78
!!! note
70
79
You need to run migrations to create the settings table: `php spark migrate -n CodeIgniter\\Settings`
71
80
81
+
**Deferred Writes**
82
+
83
+
When `deferWrites` is enabled, multiple `set()` or `forget()` calls are batched into a single database transaction at the end of the request. This significantly reduces database queries:
84
+
85
+
```php
86
+
// With deferWrites = false: 3 separate queries (INSERT/UPDATE)
87
+
$settings->set('Example.prop1', 'value1');
88
+
$settings->set('Example.prop2', 'value2');
89
+
$settings->set('Example.prop3', 'value3');
90
+
91
+
// With deferWrites = true: 1 query updating 3 properties at the end of the request
92
+
```
93
+
72
94
---
73
95
74
96
## FileHandler
@@ -80,20 +102,35 @@ This handler stores settings as PHP files and is optimized for production use wi
80
102
*`class` - The handler class. Default: `FileHandler::class`
81
103
*`path` - The directory path where settings files are stored. Default: `WRITEPATH . 'settings'`
82
104
*`writeable` - Whether this handler supports write operations. Default: `true`
105
+
*`deferWrites` - Whether to defer writes until the end of request (`post_system` event). Default: `false`
83
106
84
107
Example:
85
108
86
109
```php
87
110
public $file = [
88
-
'class' => FileHandler::class,
89
-
'path' => WRITEPATH . 'settings',
90
-
'writeable' => true,
111
+
'class' => FileHandler::class,
112
+
'path' => WRITEPATH . 'settings',
113
+
'writeable' => true,
114
+
'deferWrites' => false,
91
115
];
92
116
```
93
117
94
118
!!! note
95
119
The `FileHandler` automatically creates the directory if it doesn't exist and checks write permissions on instantiation.
96
120
121
+
**Deferred Writes**
122
+
123
+
When `deferWrites` is enabled, multiple `set()` or `forget()` calls to the same class are batched into a single file write at the end of the request. This significantly reduces I/O operations:
124
+
125
+
```php
126
+
// With deferWrites = false: 3 file writes
127
+
$settings->set('Example.prop1', 'value1');
128
+
$settings->set('Example.prop2', 'value2');
129
+
$settings->set('Example.prop3', 'value3');
130
+
131
+
// With deferWrites = true: 1 file write at end of request
0 commit comments