pub struct ResponseCache { /* private fields */ }Expand description
Two-tier response cache: in-memory LRU (hot) + SQLite (warm).
The hot cache avoids SQLite round-trips for frequently repeated prompts. On miss from hot cache, falls through to SQLite. On hit from SQLite, the entry is promoted to the hot cache.
Implementations§
Source§impl ResponseCache
impl ResponseCache
Sourcepub fn new(
workspace_dir: &Path,
ttl_minutes: u32,
max_entries: usize,
) -> Result<Self>
pub fn new( workspace_dir: &Path, ttl_minutes: u32, max_entries: usize, ) -> Result<Self>
Open (or create) the response cache database.
Sourcepub fn with_hot_cache(
workspace_dir: &Path,
ttl_minutes: u32,
max_entries: usize,
hot_max_entries: usize,
) -> Result<Self>
pub fn with_hot_cache( workspace_dir: &Path, ttl_minutes: u32, max_entries: usize, hot_max_entries: usize, ) -> Result<Self>
Open (or create) the response cache database with a custom hot cache size.
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 get(&self, key: &str) -> Result<Option<String>>
pub fn get(&self, key: &str) -> Result<Option<String>>
Look up a cached response. Returns None on miss or expired entry.
Two-tier lookup: checks the in-memory hot cache first, then falls through to SQLite. On a SQLite hit the entry is promoted to hot cache.
Sourcepub fn put(
&self,
key: &str,
model: &str,
response: &str,
token_count: u32,
) -> Result<()>
pub fn put( &self, key: &str, model: &str, response: &str, token_count: u32, ) -> Result<()>
Store a response in the cache (both hot and warm tiers).
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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>
Converts
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>
Converts
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