glimr/session/store
Session Store
Provides the session store interface for persisting session data across requests. Supports multiple backends: database (postgres/sqlite), file cache, and signed cookies. The active store is cached in persistent_term by each driver’s start_session() function.
Types
Opaque session store that dispatches to the configured backend. Stored in persistent_term at boot by the driver’s start_session() call.
pub opaque type SessionStore
Values
pub fn cache_store(store: SessionStore) -> Nil
Caches a session store in persistent_term. Called by each driver’s start_session() during app boot.
pub fn cookie_value(
session_id: String,
data: dict.Dict(String, String),
flash: dict.Dict(String, String),
) -> String
Returns the value to store in the session cookie. For server-side stores this is the session ID. For cookie-based stores this is the encoded session payload.
pub fn destroy(session_id: String) -> Nil
Destroys the session with the given ID from the store. Called when session.invalidate() is used.
pub fn gc() -> Nil
Garbage collects expired sessions. Called probabilistically by session middleware (2% chance per request).
pub fn load(
session_id: String,
) -> #(dict.Dict(String, String), dict.Dict(String, String))
Loads session data and flash data for the given session ID. Returns a tuple of (data, flash). Returns empty dicts if the session doesn’t exist.
pub fn new(
load load: fn(String) -> #(
dict.Dict(String, String),
dict.Dict(String, String),
),
save save: fn(
String,
dict.Dict(String, String),
dict.Dict(String, String),
) -> Nil,
destroy destroy: fn(String) -> Nil,
gc gc: fn() -> Nil,
) -> SessionStore
Creates a new session store with the given backend functions. Called by each driver’s start_session() to construct the store before caching it in persistent_term.
pub fn new_cookie(
load load: fn(String) -> #(
dict.Dict(String, String),
dict.Dict(String, String),
),
save save: fn(
String,
dict.Dict(String, String),
dict.Dict(String, String),
) -> Nil,
destroy destroy: fn(String) -> Nil,
gc gc: fn() -> Nil,
cookie_value cookie_value: fn(
String,
dict.Dict(String, String),
dict.Dict(String, String),
) -> String,
) -> SessionStore
Creates a new cookie-based session store. Unlike server-side stores, the session data is encoded directly into the cookie value instead of using a session ID as a reference.