cache_manager/interfaces/
cache_manager_interface.rs1use std::time::Duration;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub enum StoreConfig {
9 Moka,
10 KeyvStoreAdapter(String),
11 Cacheable,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15pub struct CacheManagerOptions {
16 pub stores: Option<Vec<StoreConfig>>,
17 pub namespace: Option<String>,
18 pub ttl: Option<u64>,
19 pub refreshThreshold: Option<u64>,
20 pub nonBlocking: Option<bool>,
21}
22
23impl CacheManagerOptions {
24 pub fn ttl_duration(&self) -> Option<Duration> {
25 self.ttl.map(Duration::from_millis)
26 }
27
28 pub fn refresh_threshold_duration(&self) -> Option<Duration> {
29 self.refreshThreshold.map(Duration::from_millis)
30 }
31
32 pub fn non_blocking(&self) -> bool {
33 self.nonBlocking.unwrap_or(false)
34 }
35}
36
37impl Default for CacheManagerOptions {
38 fn default() -> Self {
39 Self {
40 stores: None,
41 namespace: None,
42 ttl: None,
43 refreshThreshold: None,
44 nonBlocking: None,
45 }
46 }
47}