pub struct PromptCache { /* private fields */ }Expand description
Thread-safe prompt cache backed by DashMap.
Each entry carries its own TTL (defaulting to default_ttl). Expired entries are
lazily evicted on access.
Implementations§
Source§impl PromptCache
impl PromptCache
Sourcepub fn new(default_ttl: Duration) -> Self
pub fn new(default_ttl: Duration) -> Self
Create a new cache with the given default TTL for entries.
Sourcepub fn get_text(&self, key: &str) -> Option<TextPromptClient>
pub fn get_text(&self, key: &str) -> Option<TextPromptClient>
Retrieve a cached text prompt if it exists and has not expired.
Cache key format: "{name}:{version}" or "{name}:latest".
Sourcepub fn put_text(&self, key: &str, prompt: TextPromptClient)
pub fn put_text(&self, key: &str, prompt: TextPromptClient)
Insert (or replace) a text prompt in the cache using the default TTL.
Sourcepub fn get_text_expired(&self, key: &str) -> Option<TextPromptClient>
pub fn get_text_expired(&self, key: &str) -> Option<TextPromptClient>
Retrieve a cached text prompt even if it has expired.
Used for fallback behavior: when the API is unreachable, an expired cached entry is better than no entry at all.
Sourcepub fn get_chat(&self, key: &str) -> Option<ChatPromptClient>
pub fn get_chat(&self, key: &str) -> Option<ChatPromptClient>
Retrieve a cached chat prompt if it exists and has not expired.
Sourcepub fn put_chat(&self, key: &str, prompt: ChatPromptClient)
pub fn put_chat(&self, key: &str, prompt: ChatPromptClient)
Insert (or replace) a chat prompt in the cache using the default TTL.
Sourcepub fn get_chat_expired(&self, key: &str) -> Option<ChatPromptClient>
pub fn get_chat_expired(&self, key: &str) -> Option<ChatPromptClient>
Retrieve a cached chat prompt even if it has expired.
Used for fallback behavior: when the API is unreachable, an expired cached entry is better than no entry at all.
Sourcepub fn invalidate_by_prefix(&self, prefix: &str)
pub fn invalidate_by_prefix(&self, prefix: &str)
Remove all entries whose key starts with the given prefix.
Used to invalidate all cached versions/labels for a prompt name after a create or update operation.