pub struct SessionStore { /* private fields */ }Expand description
Token-keyed pool of live sessions. Threaded through AppState as
Arc<SessionStore> so the idle reaper (a detached thread) shares the same
map as request handlers.
Implementations§
Source§impl SessionStore
impl SessionStore
Sourcepub fn new(max_sessions: usize, idle_timeout: Duration) -> Self
pub fn new(max_sessions: usize, idle_timeout: Duration) -> Self
New store allowing up to max_sessions concurrent sessions, each evicted
after idle_timeout of inactivity.
Sourcepub fn create(&self, session: MongrelSession, owner: String) -> Option<String>
pub fn create(&self, session: MongrelSession, owner: String) -> Option<String>
Register a new session under a fresh opaque token. Returns the token, or
None if the store is at capacity (caller maps this to HTTP 503).
Sourcepub fn get(&self, token: &str, owner: &str) -> Option<Arc<SessionEntry>>
pub fn get(&self, token: &str, owner: &str) -> Option<Arc<SessionEntry>>
Look up a session by token, verifying the caller owns it and the session
is not closed. Returns a cloned Arc<SessionEntry> (the store lock is
released immediately; the caller holds the entry’s per-session lock for
the request duration, and must re-check is_closed() after locking).
Returns None for an unknown token, an ownership mismatch, or a closed
session.
Sourcepub fn close(&self, token: &str, owner: &str) -> bool
pub fn close(&self, token: &str, owner: &str) -> bool
Remove and drop a session, marking it closed first so any request that
already holds an Arc aborts after acquiring the lock. Returns whether a
session was removed. Rejects non-owners.
Sourcepub fn sweep_idle(&self) -> usize
pub fn sweep_idle(&self) -> usize
Evict every session idle for longer than the configured timeout, skipping
any session with an in-flight request (per-session lock held). Called
periodically by spawn_session_reaper. Returns the count evicted.
pub fn is_empty(&self) -> bool
Auto 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§
impl<T> Allocation for T
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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 more