1use std::time::Duration;
3
4#[derive(Debug, Clone)]
6pub struct MemoryConfig {
7 pub max_capacity: u64,
9
10 pub initial_capacity: usize,
12
13 pub default_ttl: Duration,
15
16 pub ttl_random_range: Option<Duration>,
19
20 pub time_to_idle: Option<Duration>,
22
23 pub system_name: String,
25}
26
27impl Default for MemoryConfig {
28 fn default() -> Self {
29 Self {
30 max_capacity: 10_000,
31 initial_capacity: 100,
32 default_ttl: Duration::from_secs(3600), ttl_random_range: Some(Duration::from_secs(300)), time_to_idle: Some(Duration::from_secs(1800)), system_name: "secra".to_string(),
36 }
37 }
38}
39
40impl MemoryConfig {
41 pub fn new(
51 max_capacity: u64,
52 default_ttl: Duration,
53 ttl_random_range: Option<Duration>,
54 ) -> Self {
55 Self {
56 max_capacity,
57 initial_capacity: 100,
58 default_ttl,
59 ttl_random_range,
60 time_to_idle: Some(Duration::from_secs(1800)),
61 system_name: "secra".to_string(),
62 }
63 }
64
65 pub fn with_system_name(mut self, system_name: String) -> Self {
73 self.system_name = system_name;
74 self
75 }
76
77 pub fn with_initial_capacity(mut self, initial_capacity: usize) -> Self {
85 self.initial_capacity = initial_capacity;
86 self
87 }
88
89 pub fn with_time_to_idle(mut self, time_to_idle: Option<Duration>) -> Self {
97 self.time_to_idle = time_to_idle;
98 self
99 }
100}