pub struct SessionRepository { /* private fields */ }Expand description
Framework-owned coordinator over a session’s cache / storage / persistence
tiers. Cheap to clone (all fields are Arc).
Implementations§
Source§impl SessionRepository
impl SessionRepository
pub fn new( cache: SessionCache, storage: Arc<dyn Storage>, persistence: Arc<LockedSessionStore>, ) -> Self
pub fn cache(&self) -> &SessionCache
pub fn storage(&self) -> &Arc<dyn Storage> ⓘ
pub fn persistence(&self) -> &Arc<LockedSessionStore> ⓘ
Sourcepub async fn load(&self, session_id: &str) -> Option<Session>
pub async fn load(&self, session_id: &str) -> Option<Session>
Load a session from the memory cache, falling back to durable storage
(and back-filling the cache on a storage hit). None if absent in both.
Sourcepub async fn try_load(&self, session_id: &str) -> Result<Option<Session>>
pub async fn try_load(&self, session_id: &str) -> Result<Option<Session>>
Like load, but surfaces storage errors instead of
swallowing them to None. Cache hit short-circuits; a storage hit
back-fills the cache.
Sourcepub async fn save(&self, session: &mut Session) -> Result<()>
pub async fn save(&self, session: &mut Session) -> Result<()>
Persist the session (merge-on-write) and refresh the cache, surfacing
storage errors. Use save_and_cache for the
fire-and-forget variant that logs and continues on failure.
Sourcepub async fn update_runtime_session<F>(
&self,
session_id: &str,
metadata_keys: &[&str],
mutate: F,
) -> Result<Option<Session>>
pub async fn update_runtime_session<F>( &self, session_id: &str, metadata_keys: &[&str], mutate: F, ) -> Result<Option<Session>>
Atomically mutate the latest durable runtime session and refresh the cache with the saved value. This is the safe path for narrow metadata indexes that can be updated concurrently with runner message writes.
Sourcepub async fn load_or_create(&self, session_id: &str, model: &str) -> Session
pub async fn load_or_create(&self, session_id: &str, model: &str) -> Session
Load a session, creating a fresh Session::new(id, model) if absent.
Sourcepub async fn load_merged(&self, session_id: &str) -> Option<Session>
pub async fn load_merged(&self, session_id: &str) -> Option<Session>
Load a session, reconciling the memory and storage copies via a preference heuristic: storage wins when it is strictly newer, or when it is the same age but still carries a pending question memory lost. Storage is never preferred when it is strictly older than memory.
The cache is refreshed cache-aside but with a no-regression guarantee:
load_merged never overwrites a newer cached session with an older
storage copy, so it is safe to call from hot read paths.
Sourcepub async fn save_and_cache(&self, session: &mut Session)
pub async fn save_and_cache(&self, session: &mut Session)
Persist the session (merge-on-write, preserving concurrent UI edits to the authoritative metadata group) and refresh the in-memory cache.
Trait Implementations§
Source§impl Clone for SessionRepository
impl Clone for SessionRepository
Source§fn clone(&self) -> SessionRepository
fn clone(&self) -> SessionRepository
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl RuntimeSessionPersistence for SessionRepository
SessionRepository is the canonical RuntimeSessionPersistence: the runtime
can persist a session through the same coordinator (merge-on-write + cache
refresh) instead of a bespoke adapter.
impl RuntimeSessionPersistence for SessionRepository
SessionRepository is the canonical RuntimeSessionPersistence: the runtime
can persist a session through the same coordinator (merge-on-write + cache
refresh) instead of a bespoke adapter.
Source§fn save_runtime_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 mut Session,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_runtime_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 mut Session,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn checkpoint_runtime_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 mut Session,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn checkpoint_runtime_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 mut Session,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn load_runtime_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Session>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_runtime_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Session>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn append_token_usage_record<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
json_line: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn append_token_usage_record<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
json_line: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Storage::append_token_usage_record). Defaults to
a no-op so non-file-backed persisters are unaffected.Source§impl SessionAccess for SessionRepository
The framework-owned SessionRepository is the canonical SessionAccess.
Server AppState delegates to its session_repo; SDK / in-process callers
can use a SessionRepository directly as a SessionAccess.
impl SessionAccess for SessionRepository
The framework-owned SessionRepository is the canonical SessionAccess.
Server AppState delegates to its session_repo; SDK / in-process callers
can use a SessionRepository directly as a SessionAccess.