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/recipes/session-handling.md
+24-3Lines changed: 24 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ This document explains how session handling works in Lucee and covers configurat
37
37
38
38
Lucee allows use of 2 types of sessions:
39
39
40
-
-"jee" - The session provided and managed by the ServletEngine, also known as "JSession"
40
+
- "jee" - The session provided and managed by the ServletEngine, also known as "JSession"
41
41
- "cfml" - The Sessions provided and managed by Lucee
42
42
43
43
You can define the type used in the Lucee Administrator or .CFConfig.json like this:
@@ -202,7 +202,7 @@ public void function logout() {
202
202
}
203
203
```
204
204
205
-
### Rotating session coookies
205
+
### Rotating session cookies
206
206
207
207
The [[function-sessionRotate]] function creates a new session (i.e. with a fresh session token) and copies over existing session data and invalidating the old session token:
208
208
@@ -221,7 +221,7 @@ if (authentication.success) {
221
221
222
222
## Security
223
223
224
-
The Session is linked with help of the key "CFID" that can be in the URL of the cookie of the user (the key "CFTOKEN" is not used by Lucee and only exists for compatibility with other CFML engines).
224
+
The Session is linked with help of the key "CFID" that can be in the URL of the cookie of the request (the key "CFTOKEN" is not used by Lucee and only exists for compatibility with other CFML engines).
225
225
226
226
Lucee first checks for "CFID" in the URL and only if not exists in the URL it looks for it in the cookie scope.
227
227
@@ -269,6 +269,26 @@ The client identification is derived from:
269
269
2. If not available, falls back to accept header
270
270
3. If no identifying information is available, reverts to standard CFID generation
271
271
272
+
## Session Change Detection
273
+
274
+
If you are using just the local memory based sessions, there is no change detection required / performed.
275
+
276
+
When using `sessionCluster` or an external cache, Lucee needs to track what has changed (which has overhead), to know whether the external cache needs to be updated.
277
+
278
+
For performance, Lucee does not constantly write back to the external cache, it enumerates the session scope to detect changes and periodically updates the cache, when it's changed / aka dirty.
279
+
280
+
If you aren't using `sessionCluster`, Lucee doesn't update the external cache on every change, it periodically writes out the session to the cache.
281
+
282
+
If the session is dirty (changes detected), you can use [[function-sessionCommit]] to force this write immediately.
283
+
284
+
With `sessionCluster` enabled, when a change in the session is detected, the change will be written out at the end of the request.
285
+
286
+
The change detection, for performance reasons, does not do a deep inspection of nested objects or components. It only checks the two top level values in the session scope, deeply nested changes will not be detected, as this is expensive (happens every request).
287
+
288
+
Storing components in the session scope is not **recommended**, it's expensive to check for changes and it adds per request overhead serializing/deserializing (read/write) and increases the stored session size.
289
+
290
+
Rather store the instance values in the session and have a component wrapper around which reads from such session properties. Such a component wrapper is loaded into the JVM memory as a class and is therefore instantly available.
291
+
272
292
## Best Practices
273
293
274
294
Lucee tries to avoid creating sessions whenever possible. It only creates a session when:
@@ -286,5 +306,6 @@ Best practices for session handling:
286
306
3. Consider security implications when choosing between URL and cookie-based session tracking
287
307
4. Implement session rotation after authentication state changes
288
308
5. Set appropriate timeout values based on your application's requirements
309
+
6. Avoid storing components in the session scope, store simple values
289
310
290
311
Since Lucee 6.2, empty sessions are only kept for up to a minute, independent of the storage used, to optimize resource usage.
0 commit comments