1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! 响应缓存模块:提供可插拔的缓存后端以减少重复 API 调用。
//!
//! # Response Caching Module
//!
//! This module provides flexible response caching capabilities with pluggable
//! backends, reducing API calls and improving response times for repeated requests.
//!
//! ## Overview
//!
//! Caching is valuable for:
//! - Reducing API costs by avoiding duplicate requests
//! - Improving response latency for repeated queries
//! - Enabling offline or degraded mode operation
//! - Supporting development and testing workflows
//!
//! ## Key Components
//!
//! | Component | Description |
//! |-----------|-------------|
//! | [`CacheManager`] | High-level cache management with TTL and statistics |
//! | [`CacheConfig`] | Configuration for cache behavior and limits |
//! | [`CacheBackend`] | Trait for implementing custom cache backends |
//! | [`MemoryCache`] | In-memory LRU cache implementation |
//! | [`NullCache`] | No-op cache for disabling caching |
//! | [`CacheKey`] | Cache key generation from request parameters |
//!
//! ## Example
//!
//! ```rust
//! use ai_lib_contact::cache::{CacheManager, CacheConfig, MemoryCache};
//! use std::time::Duration;
//!
//! // Create an in-memory cache with 1-hour TTL
//! let config = CacheConfig::new()
//! .with_ttl(Duration::from_secs(3600))
//! .with_enabled(true);
//! let cache = CacheManager::new(config, Box::new(MemoryCache::new(1000)));
//! ```
//!
//! ## Cache Key Generation
//!
//! Cache keys are generated from:
//! - Model identifier
//! - Message content (hashed)
//! - Request parameters (temperature, max_tokens, etc.)
//!
//! This ensures identical requests return cached responses while different
//! parameters generate new cache entries.
pub use ;
pub use ;
pub use ;