pub struct CacheClient<C> { /* private fields */ }Expand description
An LLMClient wrapper that caches complete responses in a KvStore.
On complete, the cache is checked first; a fresh (non-expired) hit returns
the stored response without calling the inner client. On a miss the inner
client is called and a successful response is stored. Cache read/write
errors are non-fatal — a failed read falls through to the inner client, a
failed write is dropped, and the response is still returned.
stream_complete is always delegated to the inner client (never cached).
Implementations§
Source§impl<C> CacheClient<C>
impl<C> CacheClient<C>
Sourcepub fn new(inner: C, store: Arc<dyn KvStore>) -> Self
pub fn new(inner: C, store: Arc<dyn KvStore>) -> Self
Wrap inner with a response cache backed by store (no expiry).
Sourcepub fn with_ttl(inner: C, store: Arc<dyn KvStore>, ttl: Duration) -> Self
pub fn with_ttl(inner: C, store: Arc<dyn KvStore>, ttl: Duration) -> Self
Wrap inner with a response cache whose entries expire after ttl.
Expired entries are lazily evicted on read (treated as a miss). A TTL
bounds staleness; to bound total size, wrap the KvStore with an
evicting implementation — CacheClient does not enforce a size cap.
Trait Implementations§
Source§impl<C: LLMClient> LLMClient for CacheClient<C>
impl<C: LLMClient> LLMClient for CacheClient<C>
Source§fn complete<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn complete<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn model_name(&self) -> &str
fn model_name(&self) -> &str
Source§fn stream_complete<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream_complete<'life0, 'async_trait>(
&'life0 self,
request: LLMRequest,
) -> Pin<Box<dyn Future<Output = Result<LLMStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl<C> !RefUnwindSafe for CacheClient<C>
impl<C> !UnwindSafe for CacheClient<C>
impl<C> Freeze for CacheClient<C>where
C: Freeze,
impl<C> Send for CacheClient<C>where
C: Send,
impl<C> Sync for CacheClient<C>where
C: Sync,
impl<C> Unpin for CacheClient<C>where
C: Unpin,
impl<C> UnsafeUnpin for CacheClient<C>where
C: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.