use serde::{Deserialize, Serialize}; use crate::redis::RedisConfig; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(default)] pub struct CacheConfig { pub l1_capacity: u64, pub l1_ttl_secs: Option, pub l1_tti_secs: Option, pub default_ttl_secs: Option, pub backfill_enabled: bool, pub redis: RedisConfig, } impl Default for CacheConfig { fn default() -> Self { Self { l1_capacity: 10_000, l1_ttl_secs: None, l1_tti_secs: None, default_ttl_secs: None, backfill_enabled: true, redis: RedisConfig::default(), } } } impl CacheConfig { pub fn new(redis: RedisConfig) -> Self { Self { redis, ..Self::default() } } pub fn with_l1_capacity(mut self, capacity: u64) -> Self { self.l1_capacity = capacity; self } pub fn with_l1_ttl_secs(mut self, secs: u64) -> Self { self.l1_ttl_secs = Some(secs); self } pub fn with_l1_tti_secs(mut self, secs: u64) -> Self { self.l1_tti_secs = Some(secs); self } pub fn with_default_ttl_secs(mut self, secs: u64) -> Self { self.default_ttl_secs = Some(secs); self } pub fn with_backfill(mut self, enabled: bool) -> Self { self.backfill_enabled = enabled; self } pub fn validate(&self) -> Result<(), String> { if self.l1_capacity == 0 { return Err("cache.l1_capacity must be greater than 0".to_string()); } self.redis.validate().map(|_| ()) } }