pub struct CachingSessionStore<Cache, Store> { /* private fields */ }Expand description
Two-tier SessionStore composed of a cache frontend and a store backend.
Reads hit the cache first; on miss, they fall through to the backend and populate the cache. Writes go to both tiers. Deletes remove from both.
This lets users pair a fast in-process cache (e.g. MemorySessionStore)
with a durable backend (e.g. a Redis-backed store), keeping in-memory
read performance while gaining cross-instance durability.
Mirrors tower_sessions_core::session_store::CachingSessionStore.
§Example
use std::sync::Arc;
use tower_mcp::session_store::{CachingSessionStore, MemorySessionStore, SessionStore};
// In production the backend would be a Redis/Postgres/etc store type.
let backend = MemorySessionStore::new();
let cache = MemorySessionStore::new();
let store: Arc<dyn SessionStore> =
Arc::new(CachingSessionStore::new(cache, backend));Implementations§
Source§impl<Cache, Store> CachingSessionStore<Cache, Store>
impl<Cache, Store> CachingSessionStore<Cache, Store>
Trait Implementations§
Source§impl<Cache: Clone, Store: Clone> Clone for CachingSessionStore<Cache, Store>
impl<Cache: Clone, Store: Clone> Clone for CachingSessionStore<Cache, Store>
Source§fn clone(&self) -> CachingSessionStore<Cache, Store>
fn clone(&self) -> CachingSessionStore<Cache, Store>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<Cache, Store> SessionStore for CachingSessionStore<Cache, Store>where
Cache: SessionStore,
Store: SessionStore,
impl<Cache, Store> SessionStore for CachingSessionStore<Cache, Store>where
Cache: SessionStore,
Store: SessionStore,
Source§fn create<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 mut SessionRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn create<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 mut SessionRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Create a new session record. Read more
Source§fn save<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 SessionRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save<'life0, 'life1, 'async_trait>(
&'life0 self,
record: &'life1 SessionRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Persist an existing session record. The ID is trusted.
Auto Trait Implementations§
impl<Cache, Store> Freeze for CachingSessionStore<Cache, Store>
impl<Cache, Store> RefUnwindSafe for CachingSessionStore<Cache, Store>where
Cache: RefUnwindSafe,
Store: RefUnwindSafe,
impl<Cache, Store> Send for CachingSessionStore<Cache, Store>
impl<Cache, Store> Sync for CachingSessionStore<Cache, Store>
impl<Cache, Store> Unpin for CachingSessionStore<Cache, Store>
impl<Cache, Store> UnsafeUnpin for CachingSessionStore<Cache, Store>where
Cache: UnsafeUnpin,
Store: UnsafeUnpin,
impl<Cache, Store> UnwindSafe for CachingSessionStore<Cache, Store>where
Cache: UnwindSafe,
Store: UnwindSafe,
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
Mutably borrows from an owned value. Read more