1use std::time::Duration;
4
5#[derive(Clone, Debug)]
7pub struct CacheConfig {
8 pub max_entries: usize,
10 pub ttl: Duration,
12 pub key_prefix: String,
14 pub semantic_matching: bool,
16 pub similarity_threshold: f32,
18}
19
20impl Default for CacheConfig {
21 fn default() -> Self {
22 Self {
23 max_entries: 1000,
24 ttl: Duration::from_secs(3600), key_prefix: "ai-agents:cache:".to_string(),
26 semantic_matching: false,
27 similarity_threshold: 0.92,
28 }
29 }
30}
31
32impl CacheConfig {
33 pub fn new() -> Self {
35 Self::default()
36 }
37
38 pub fn max_entries(mut self, max: usize) -> Self {
40 self.max_entries = max;
41 self
42 }
43
44 pub fn ttl(mut self, ttl: Duration) -> Self {
46 self.ttl = ttl;
47 self
48 }
49
50 pub fn key_prefix(mut self, prefix: impl Into<String>) -> Self {
52 self.key_prefix = prefix.into();
53 self
54 }
55
56 pub fn with_semantic_matching(mut self, threshold: f32) -> Self {
58 self.semantic_matching = true;
59 self.similarity_threshold = threshold.clamp(0.0, 1.0);
60 self
61 }
62
63 pub fn short_lived() -> Self {
65 Self {
66 ttl: Duration::from_secs(300),
67 ..Default::default()
68 }
69 }
70
71 pub fn long_lived() -> Self {
73 Self {
74 ttl: Duration::from_secs(86400),
75 max_entries: 5000,
76 ..Default::default()
77 }
78 }
79
80 pub fn session() -> Self {
82 Self {
83 ttl: Duration::from_secs(7200),
84 max_entries: 500,
85 key_prefix: "ai-agents:session:".to_string(),
86 ..Default::default()
87 }
88 }
89
90 pub fn for_agents() -> Self {
92 Self {
93 ttl: Duration::from_secs(3600),
94 max_entries: 2000,
95 key_prefix: "ai-agents:responses:".to_string(),
96 ..Default::default()
97 }
98 }
99}