aws_secretsmanager_cache/
config.rs1const DEFAULT_MAX_CACHE_SIZE: usize = 1024;
2const DEFAULT_CACHE_ITEM_TTL: u128 = 3600000000000; const DEFAULT_VERSION_STAGE: &str = "AWSCURRENT";
4
5pub struct CacheConfig {
12 pub max_cache_size: usize,
19
20 pub cache_item_ttl: u128,
27
28 pub version_stage: String,
32}
33
34impl CacheConfig {
35 pub fn new() -> Self {
42 CacheConfig {
43 max_cache_size: DEFAULT_MAX_CACHE_SIZE,
44 cache_item_ttl: DEFAULT_CACHE_ITEM_TTL,
45 version_stage: DEFAULT_VERSION_STAGE.to_string(),
46 }
47 }
48
49 pub fn max_cache_size(mut self, max_cache_size: usize) -> Self {
51 self.max_cache_size = max_cache_size;
52 self
53 }
54
55 pub fn cache_item_ttl(mut self, cache_item_ttl: u128) -> Self {
57 self.cache_item_ttl = cache_item_ttl;
58 self
59 }
60}
61
62impl Default for CacheConfig {
63 fn default() -> Self {
64 Self::new()
65 }
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71 use std::time;
72
73 #[test]
74 fn cache_config_default() {
75 let cache_config = CacheConfig::new();
76
77 assert_eq!(cache_config.cache_item_ttl, DEFAULT_CACHE_ITEM_TTL);
78 assert_eq!(cache_config.max_cache_size, DEFAULT_MAX_CACHE_SIZE);
79 assert_eq!(cache_config.version_stage, DEFAULT_VERSION_STAGE);
80 }
81
82 #[test]
83 fn cache_config_custom() {
84 let custom_cache_ttl = time::Duration::from_secs(30).as_nanos();
85 let cache_config = CacheConfig::new()
86 .max_cache_size(10)
87 .cache_item_ttl(custom_cache_ttl);
88
89 assert_eq!(cache_config.cache_item_ttl, custom_cache_ttl);
90 assert_eq!(cache_config.max_cache_size, 10);
91 assert_eq!(cache_config.version_stage, DEFAULT_VERSION_STAGE);
92 }
93
94 #[test]
95 fn cache_config_partial_config() {
96 let cache_config = CacheConfig::new().max_cache_size(10);
97
98 assert_eq!(cache_config.cache_item_ttl, DEFAULT_CACHE_ITEM_TTL);
99 assert_eq!(cache_config.max_cache_size, 10);
100 assert_eq!(cache_config.version_stage, DEFAULT_VERSION_STAGE);
101 }
102}