pub struct SessionManager { /* private fields */ }Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(ttl: Duration, max_turns: usize) -> Self
pub fn new(ttl: Duration, max_turns: usize) -> Self
Creates the manager and spawns the background TTL sweeper.
Sourcepub fn with_cap(ttl: Duration, max_turns: usize, max_sessions: usize) -> Self
pub fn with_cap(ttl: Duration, max_turns: usize, max_sessions: usize) -> Self
Creates the manager with a custom concurrent-session cap. Values
of 0 disable the cap (unbounded).
pub fn create(&self, agent_id: impl Into<String>) -> Session
Sourcepub fn get(&self, id: Uuid) -> Option<Session>
pub fn get(&self, id: Uuid) -> Option<Session>
Returns the session, updating last_access. Returns None if not found.
Sourcepub fn get_or_create(&self, id: Uuid, agent_id: impl Into<String>) -> Session
pub fn get_or_create(&self, id: Uuid, agent_id: impl Into<String>) -> Session
Returns existing session or creates a new one bound to agent_id.
Sourcepub fn update(&self, session: Session) -> bool
pub fn update(&self, session: Session) -> bool
Replaces session state. Returns false if the session does not exist.
The replacement is atomic via DashMap’s get_mut entry lock — this
prevents a race where delete() runs between a check and insert
and the update silently resurrects the removed session.
Sourcepub fn push_message(&self, id: Uuid, interaction: Interaction) -> bool
pub fn push_message(&self, id: Uuid, interaction: Interaction) -> bool
Atomically append an interaction to the session’s history while
holding the DashMap entry lock. The older pattern — clone → mutate clone → update(clone) — could drop history when two
handlers raced on the same session (both read the pre-trim
state, both pushed their entry, the second overwrote the
first’s trim). Returns false if the session no longer exists.
Sourcepub fn delete(&self, id: Uuid) -> bool
pub fn delete(&self, id: Uuid) -> bool
Removes a session and fires every registered on_expire callback.
Returns true if it existed.
pub fn active_count(&self) -> usize
Sourcepub fn on_expire<F>(&self, f: F)
pub fn on_expire<F>(&self, f: F)
Register a callback fired when a session is dropped — either by
explicit delete() or by the TTL sweeper. Each invocation runs on
its own tokio::spawn, so callbacks must not assume caller context
and should capture owned handles (Arc clones) from the closure’s
environment. Safe to call multiple times; callbacks fire in the
registration order snapshot at the moment of expiry.
Trait Implementations§
Source§impl Clone for SessionManager
impl Clone for SessionManager
Source§fn clone(&self) -> SessionManager
fn clone(&self) -> SessionManager
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 !RefUnwindSafe for SessionManager
impl !UnwindSafe for SessionManager
impl Freeze for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin for SessionManager
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
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 more