pub struct LLMCache { /* private fields */ }Expand description
Implementations§
Source§impl LLMCache
impl LLMCache
pub fn new() -> Self
pub fn with_config(config: CacheConfig) -> Self
Sourcepub fn build_key(messages: &[Message], model: &str) -> Result<String, String>
pub fn build_key(messages: &[Message], model: &str) -> Result<String, String>
从消息列表生成缓存键
将消息列表序列化为 JSON 字符串作为键。 包含 model 名称以确保不同模型的调用不互相影响。 如果序列化失败,返回错误而非回退到空字符串(M34)。
Sourcepub async fn get(&self, key: &str) -> Option<CachedLLMResult>
pub async fn get(&self, key: &str) -> Option<CachedLLMResult>
获取缓存结果
如果发现过期条目,会立即删除(H36)。命中时会刷新 cached_at,
使缓存保持真 LRU 语义(Q7:命中后该条目成为最近使用)。
Sourcepub async fn evict_expired(&self) -> usize
pub async fn evict_expired(&self) -> usize
移除过期条目
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for LLMCache
impl !RefUnwindSafe for LLMCache
impl !UnwindSafe for LLMCache
impl Send for LLMCache
impl Sync for LLMCache
impl Unpin for LLMCache
impl UnsafeUnpin for LLMCache
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