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) -> SessionStore
pub fn new(ttl_secs: u64) -> SessionStore
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).
Trait Implementations§
Source§impl Clone for SessionStore
impl Clone for SessionStore
Source§fn clone(&self) -> SessionStore
fn clone(&self) -> SessionStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SessionStore
impl RefUnwindSafe for SessionStore
impl Send for SessionStore
impl Sync for SessionStore
impl Unpin for SessionStore
impl UnsafeUnpin for SessionStore
impl UnwindSafe for SessionStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.