Skip to content

Commit 3ccbbe6

Browse files
committed
Document session expiration / rolling sessions
1 parent c0fab01 commit 3ccbbe6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

plain-sessions/plain/sessions/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [Overview](#overview)
66
- [Basic usage](#basic-usage)
77
- [Session configuration](#session-configuration)
8+
- [Session expiration](#session-expiration)
89
- [Session management](#session-management)
910
- [Flushing sessions](#flushing-sessions)
1011
- [Cycling session keys](#cycling-session-keys)
@@ -84,12 +85,21 @@ SESSION_COOKIE_HTTPONLY = True
8485
SESSION_COOKIE_SAMESITE = "Lax"
8586

8687
# Whether to save the session data on every request
88+
# False (default) = save only when modified, True = save on every access
8789
SESSION_SAVE_EVERY_REQUEST = False
8890

8991
# Whether a user's session cookie expires when the browser is closed
9092
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
9193
```
9294

95+
## Session expiration
96+
97+
Sessions expire `SESSION_COOKIE_AGE` seconds after they are **last saved** (not last accessed).
98+
99+
By default (`SESSION_SAVE_EVERY_REQUEST = False`), sessions are only saved when modified. For authenticated users, this means the expiration timer resets on login/logout but **not** when just browsing pages. Users will be logged out after `SESSION_COOKIE_AGE` even if actively using the site.
100+
101+
To extend sessions on every page access, set `SESSION_SAVE_EVERY_REQUEST = True`. This creates a sliding window where users stay logged in as long as they visit within `SESSION_COOKIE_AGE`, but increases database writes
102+
93103
## Session management
94104

95105
The [`SessionStore`](./core.py#SessionStore) class provides additional methods for managing sessions:

0 commit comments

Comments
 (0)