use std::time::Duration;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum StoreConfig {
Moka,
KeyvStoreAdapter(String),
Cacheable,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CacheManagerOptions {
pub stores: Option<Vec<StoreConfig>>,
pub namespace: Option<String>,
pub ttl: Option<u64>,
pub refreshThreshold: Option<u64>,
pub nonBlocking: Option<bool>,
}
impl CacheManagerOptions {
pub fn ttl_duration(&self) -> Option<Duration> {
self.ttl.map(Duration::from_millis)
}
pub fn refresh_threshold_duration(&self) -> Option<Duration> {
self.refreshThreshold.map(Duration::from_millis)
}
pub fn non_blocking(&self) -> bool {
self.nonBlocking.unwrap_or(false)
}
}
impl Default for CacheManagerOptions {
fn default() -> Self {
Self {
stores: None,
namespace: None,
ttl: None,
refreshThreshold: None,
nonBlocking: None,
}
}
}