use std::time::Duration;
#[derive(Debug, Clone)]
pub struct CacheConfig {
pub max_entries: usize,
pub ttl: Duration,
pub enabled: bool,
}
impl Default for CacheConfig {
fn default() -> Self {
Self {
max_entries: 100,
ttl: Duration::from_secs(300), enabled: true,
}
}
}
impl CacheConfig {
pub fn new(max_entries: usize, ttl: Duration, enabled: bool) -> Self {
Self {
max_entries,
ttl,
enabled,
}
}
pub fn disabled() -> Self {
Self {
max_entries: 0,
ttl: Duration::from_secs(0),
enabled: false,
}
}
pub fn from_env() -> Self {
Self {
max_entries: std::env::var("BSSH_CACHE_SIZE")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(100),
ttl: Duration::from_secs(
std::env::var("BSSH_CACHE_TTL")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(300),
),
enabled: std::env::var("BSSH_CACHE_ENABLED")
.map(|s| s.to_lowercase() != "false" && s != "0")
.unwrap_or(true),
}
}
}