pub struct InMemoryCache { /* private fields */ }Expand description
In-memory cache implementation using LRU eviction.
This cache provides fast local storage with automatic eviction of least recently used entries when capacity is reached.
§Examples
use ultrafast_models_sdk::cache::{InMemoryCache, Cache, CachedResponse};
use std::time::Duration;
let cache = InMemoryCache::new(1000); // 1000 entries capacity
let response = CachedResponse::new(chat_response, Duration::from_secs(3600));
cache.set("key", response, Duration::from_secs(3600));
if let Some(cached) = cache.get("key") {
println!("Cache hit: {}", cached.response.choices[0].message.content);
}Implementations§
Trait Implementations§
Source§impl Cache for InMemoryCache
impl Cache for InMemoryCache
Source§fn get(&self, key: &str) -> Option<CachedResponse>
fn get(&self, key: &str) -> Option<CachedResponse>
Retrieve a cached response by key. Read more
Source§fn set(&self, key: &str, response: CachedResponse, _ttl: Duration)
fn set(&self, key: &str, response: CachedResponse, _ttl: Duration)
Store a response in the cache. Read more
Source§fn invalidate(&self, key: &str)
fn invalidate(&self, key: &str)
Remove a specific entry from the cache. Read more
Auto Trait Implementations§
impl Freeze for InMemoryCache
impl RefUnwindSafe for InMemoryCache
impl Send for InMemoryCache
impl Sync for InMemoryCache
impl Unpin for InMemoryCache
impl UnwindSafe for InMemoryCache
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