pub struct PromptCache { /* private fields */ }Expand description
Thread-safe, content-addressed LRU prompt cache.
Clone-cheap: all clones share the same underlying data.
Implementations§
Source§impl PromptCache
impl PromptCache
Sourcepub fn new(config: CacheConfig) -> Self
pub fn new(config: CacheConfig) -> Self
Create a new cache with the given configuration.
Sourcepub fn get(&self, model_id: &str, prompt: &str) -> Option<Vec<String>>
pub fn get(&self, model_id: &str, prompt: &str) -> Option<Vec<String>>
Look up a cached response for (model_id, prompt).
Returns None on a cache miss or if the entry has expired.
Updates the LRU order and hit counter on a hit.
Prompts longer than max_prompt_len are always treated as misses.
Sourcepub fn insert(
&self,
model_id: &str,
prompt: &str,
response: Vec<String>,
ttl: Option<Duration>,
)
pub fn insert( &self, model_id: &str, prompt: &str, response: Vec<String>, ttl: Option<Duration>, )
Insert a response for (model_id, prompt).
ttl: whenNone, the cache’sdefault_ttlis used.- Prompts longer than
max_prompt_lenare silently dropped. - If the cache is full the LRU entry is evicted first.
Sourcepub fn evict_expired(&self) -> usize
pub fn evict_expired(&self) -> usize
Evict all entries whose TTL has elapsed.
Returns the number of entries removed.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Return a snapshot of current cache statistics.
Trait Implementations§
Source§impl Clone for PromptCache
impl Clone for PromptCache
Source§fn clone(&self) -> PromptCache
fn clone(&self) -> PromptCache
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PromptCache
impl RefUnwindSafe for PromptCache
impl Send for PromptCache
impl Sync for PromptCache
impl Unpin for PromptCache
impl UnsafeUnpin for PromptCache
impl UnwindSafe for PromptCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§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>
Wrap the input message
T in a tonic::Request