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
+11-6Lines changed: 11 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,8 @@ public $handlers = ['database'];
29
29
### Deferred writes
30
30
31
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.
32
+
are batched and persisted efficiently at the end of the request during the `post_system` event. This minimizes the number of
33
+
database queries or file I/O operations, improving performance for write-heavy operations.
33
34
34
35
### Multiple handlers
35
36
@@ -80,17 +81,19 @@ public $database = [
80
81
81
82
**Deferred Writes**
82
83
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
+
When `deferWrites` is enabled, multiple `set()` or `forget()` calls are batched and persisted in a single transaction at the end of the request. This significantly reduces database queries:
84
85
85
86
```php
86
-
// With deferWrites = false: 3 separate queries (INSERT/UPDATE)
87
+
// With deferWrites = false: 1 SELECT (hydrates all settings for context) + 3 separate INSERT/UPDATE queries
87
88
$settings->set('Example.prop1', 'value1');
88
89
$settings->set('Example.prop2', 'value2');
89
90
$settings->set('Example.prop3', 'value3');
90
91
91
-
// With deferWrites = true: 1 query updating 3 properties at the end of the request
92
+
// With deferWrites = true: 1 SELECT + 1 INSERT batch + 1 UPDATE batch (all batched at end of request)
92
93
```
93
94
95
+
The deferred approach is especially beneficial when updating existing records or performing many operations in a single request.
96
+
94
97
---
95
98
96
99
## FileHandler
@@ -123,14 +126,16 @@ public $file = [
123
126
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
127
125
128
```php
126
-
// With deferWrites = false: 3 file writes
129
+
// With deferWrites = false: 1 file read (hydrates all settings for class) + 3 separate file writes
127
130
$settings->set('Example.prop1', 'value1');
128
131
$settings->set('Example.prop2', 'value2');
129
132
$settings->set('Example.prop3', 'value3');
130
133
131
-
// With deferWrites = true: 1 file write at end of request
134
+
// With deferWrites = true: 1 file read + 1 file write (all changes batched at end of request)
132
135
```
133
136
137
+
The deferred approach is especially beneficial when updating multiple properties in the same class.
0 commit comments