rainier-session
Sessions: the [Session] bag a handler reads and writes, the
[SessionStore] port it is persisted through, and the [StartSession]
middleware that ties them to a cookie.
use ;
use ;
use ;
use Arc;
# async
The session is on the request, not on a facade
Laravel's Session::get('user_id') works because its container rebinds a
request-scoped session per request. Rainier's facades resolve from a
process-global application, so there is nothing honest for
Session::instance().get(…) to return — with two requests in flight, which
one would it be?
So the split is explicit:
request.session() |
this request's bag |
[SessionManager] (the Session facade) |
the store and its settings |
The facade is for what genuinely is application-wide: reading or destroying a session by id, and collecting expired ones.
Flash data
flash stores a value for exactly one further request —
the redirect-then-show-a-message pattern, with nothing to remember to clean
up:
# use ;
let session = new;
session.flash.unwrap;
// …the request ends, and the next one can read it.
let next = restore;
assert_eq!;
// …and the one after that cannot.
let later = restore;
assert!;
Drivers
| Driver | Survives a restart | Shared | Revocable | Note |
|---|---|---|---|---|
[MemorySessionStore] |
no | no | yes | development |
[DatabaseSessionStore] |
yes | yes | yes | never evicts |
[CacheSessionStore] |
depends | yes | yes | expires itself; can evict |
[CookieSessionStore] |
yes | yes | no | no server state at all |
A memory store behind a load balancer makes a user's session appear to vanish and reappear as they are routed around, which looks like a bug in your login code and is not.
The cookie driver is the odd one: the whole session travels encrypted in the cookie, so there is nothing to store and nothing to expire — and nothing to revoke either. A session you cannot see is a session you cannot end.