pub struct SessionStore { /* private fields */ }Expand description
Thread-safe in-memory session store with TTL-based expiry.
Cloning is cheap — all clones share the same backing map via Arc.
Place one instance in your application state and share it across handlers.
Implementations§
Source§impl SessionStore
impl SessionStore
Sourcepub fn new(ttl_secs: u64) -> Self
pub fn new(ttl_secs: u64) -> Self
Create a new store where sessions expire ttl_secs seconds after
creation.
Sourcepub fn create(&self) -> Session
pub fn create(&self) -> Session
Create a new empty session with a generated ID, insert it into the
store, and return it. Mutate the session then call save.
Sourcepub fn create_with_id(&self, id: String) -> Session
pub fn create_with_id(&self, id: String) -> Session
Create a new empty session using id (caller supplies the value,
e.g. from a CSPRNG). Inserts the session and returns it.
Sourcepub fn load(&self, id: &str) -> Option<Session>
pub fn load(&self, id: &str) -> Option<Session>
Load a session by ID. Returns None if unknown or expired.
Sourcepub fn save(&self, session: &Session)
pub fn save(&self, session: &Session)
Persist a session’s data back to the store. No-op if the session ID is no longer present (e.g. already destroyed or expired and purged).
Sourcepub fn destroy(&self, id: &str)
pub fn destroy(&self, id: &str)
Delete a session immediately. Also clear the client cookie using
destroy_cookie.
Sourcepub fn purge_expired(&self)
pub fn purge_expired(&self)
Remove all sessions whose TTL has elapsed. Call periodically to reclaim memory (e.g. once per minute from a background thread).