pub struct SessionStoreCache { /* private fields */ }Expand description
LRU-bounded, thread-safe cache of open per-palace chat-session stores.
Why/What: see the module docs. Cloning is cheap — callers share one instance
behind an Arc on AppState.
Test: see the module-level test list.
Implementations§
Source§impl SessionStoreCache
impl SessionStoreCache
Sourcepub fn with_max_open(max_open: usize) -> Self
pub fn with_max_open(max_open: usize) -> Self
Build a cache with an explicit resident-handle cap.
Why: tests force eviction with a tiny cap; operators tune production via
SessionStoreCache::from_env.
What: clamps max_open to at least 1 and opens an unbounded LruCache
that SessionStoreCache::trim holds down to that cap.
Test: tests::open_handles_are_bounded_by_cap.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Build a cache whose cap comes from the environment.
Why: the daemon’s construction path wants the operator-tunable value.
What: with_max_open(max_open_session_stores_from_env()).
Test: tests::env_override_is_honoured.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
The resident-handle cap this cache enforces.
Test: tests::env_override_is_honoured.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of stores currently resident (open) in the cache.
Test: tests::open_handles_are_bounded_by_cap.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether no store is currently resident.
Test: tests::remove_drops_cached_handle.
Sourcepub fn get_or_open(
&self,
palace_id: &str,
dir: &Path,
) -> Result<Arc<ChatSessionStore>>
pub fn get_or_open( &self, palace_id: &str, dir: &Path, ) -> Result<Arc<ChatSessionStore>>
Return the cached store for palace_id, opening it under dir on miss.
Why: the single entry point callers use, so the mutex-held open (which
enforces one-store-per-palace) cannot be bypassed.
What: promotes an existing entry to most-recently-used and returns it;
on a miss creates dir, opens dir/chat_sessions.db (rewritten by
ChatSessionStore::open to chat_sessions.redb), inserts it, then
trims the cold end back to the cap.
Test: tests::evicted_store_reopens_with_data_intact,
tests::concurrent_callers_share_one_store.
Sourcepub fn remove(&self, palace_id: &str)
pub fn remove(&self, palace_id: &str)
Drop the cached handle for palace_id, closing its fd if unused.
Why: palace deletion must not leave a handle pinning the inode of a
directory that has just been unlinked — the exact shape of the 844
deleted-but-open handles measured in #4639.
What: LruCache::pop; a no-op when the palace was never opened. If a
caller still holds an Arc, that caller’s handle stays valid until it
drops (Arc semantics) — the cache simply stops handing it out.
Test: tests::remove_drops_cached_handle.
Trait Implementations§
Source§impl Debug for SessionStoreCache
impl Debug for SessionStoreCache
Auto Trait Implementations§
impl !Freeze for SessionStoreCache
impl !RefUnwindSafe for SessionStoreCache
impl !UnwindSafe for SessionStoreCache
impl Send for SessionStoreCache
impl Sync for SessionStoreCache
impl Unpin for SessionStoreCache
impl UnsafeUnpin for SessionStoreCache
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> 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