pub struct LlmCache<'conn> { /* private fields */ }Expand description
Persistent key-value cache backed by the llm_cache SQLite table.
Entries expire after the TTL supplied to put elapses.
Expired entries are invisible to get but remain in the
database until purge_expired is called.
Implementations§
Source§impl<'conn> LlmCache<'conn>
impl<'conn> LlmCache<'conn>
Sourcepub const fn new(conn: &'conn Connection) -> Self
pub const fn new(conn: &'conn Connection) -> Self
Wraps a database connection.
Sourcepub fn get(&self, key: &str) -> Result<Option<String>, TalonError>
pub fn get(&self, key: &str) -> Result<Option<String>, TalonError>
Returns the cached value for key if it exists and has not expired.
§Errors
Returns TalonError::Sqlite on a database error.
Sourcepub fn put(&self, key: &str, value: &str, ttl_ms: u64) -> Result<(), TalonError>
pub fn put(&self, key: &str, value: &str, ttl_ms: u64) -> Result<(), TalonError>
Stores value under key with a time-to-live of ttl_ms milliseconds.
Overwrites any existing entry for the same key.
§Errors
Returns TalonError::Sqlite on a database error.
Sourcepub fn purge_expired(&self) -> Result<usize, TalonError>
pub fn purge_expired(&self) -> Result<usize, TalonError>
Deletes all entries whose TTL has elapsed.
Returns the number of rows removed.
§Errors
Returns TalonError::Sqlite on a database error.
Trait Implementations§
Auto Trait Implementations§
impl<'conn> Freeze for LlmCache<'conn>
impl<'conn> !RefUnwindSafe for LlmCache<'conn>
impl<'conn> !Send for LlmCache<'conn>
impl<'conn> !Sync for LlmCache<'conn>
impl<'conn> Unpin for LlmCache<'conn>
impl<'conn> UnsafeUnpin for LlmCache<'conn>
impl<'conn> !UnwindSafe for LlmCache<'conn>
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> 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