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 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.
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