pub struct ResponseCache { /* private fields */ }Expand description
Response cache backed by a dedicated SQLite database.
Implementations§
Source§impl ResponseCache
impl ResponseCache
Sourcepub async fn new(
db_dir: &Path,
ttl_minutes: u32,
max_entries: usize,
) -> MemoryResult<Self>
pub async fn new( db_dir: &Path, ttl_minutes: u32, max_entries: usize, ) -> MemoryResult<Self>
Open (or create) the response cache database at {db_dir}/response_cache.db.
Sourcepub fn cache_key(
model: &str,
system_prompt: Option<&str>,
user_prompt: &str,
) -> String
pub fn cache_key( model: &str, system_prompt: Option<&str>, user_prompt: &str, ) -> String
Build a deterministic cache key from model + system prompt + user prompt.
Sourcepub fn cache_key_scoped(
model: &str,
system_prompt: Option<&str>,
user_prompt: &str,
scope: &ResponseCacheScope,
) -> String
pub fn cache_key_scoped( model: &str, system_prompt: Option<&str>, user_prompt: &str, scope: &ResponseCacheScope, ) -> String
Build a deterministic cache key that is partitioned by tenant and source bindings.
Sourcepub async fn get(&self, key: &str) -> MemoryResult<Option<String>>
pub async fn get(&self, key: &str) -> MemoryResult<Option<String>>
Look up a cached response. Returns None on miss or if the entry has expired.
Sourcepub async fn put(
&self,
key: &str,
model: &str,
response: &str,
token_count: u32,
) -> MemoryResult<()>
pub async fn put( &self, key: &str, model: &str, response: &str, token_count: u32, ) -> MemoryResult<()>
Store a response in the cache, evicting expired or least-recently-used entries.
pub async fn put_scoped( &self, key: &str, model: &str, response: &str, token_count: u32, scope: &ResponseCacheScope, ) -> MemoryResult<()>
pub async fn invalidate_source_binding( &self, tenant_org_id: &str, tenant_workspace_id: &str, tenant_deployment_id: Option<&str>, source_binding_id: &str, ) -> MemoryResult<usize>
pub async fn invalidate_tenant( &self, tenant_org_id: &str, tenant_workspace_id: &str, tenant_deployment_id: Option<&str>, ) -> MemoryResult<usize>
Sourcepub async fn stats(&self) -> MemoryResult<(usize, u64, u64)>
pub async fn stats(&self) -> MemoryResult<(usize, u64, u64)>
Return cache statistics: (total_entries, total_hits, estimated_tokens_saved).
Sourcepub async fn clear(&self) -> MemoryResult<usize>
pub async fn clear(&self) -> MemoryResult<usize>
Clear all cached entries.
Auto Trait Implementations§
impl Freeze for ResponseCache
impl !RefUnwindSafe for ResponseCache
impl Send for ResponseCache
impl Sync for ResponseCache
impl Unpin for ResponseCache
impl UnsafeUnpin for ResponseCache
impl !UnwindSafe for ResponseCache
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