baichun-framework-cache 0.1.0

Cache module for Baichun-Rust framework
Documentation
use serde::{Deserialize, Serialize};

/// Cache mode
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
pub enum CacheMode {
    /// Local cache only
    Local,
    /// Redis cache only
    Redis,
    /// Multilevel cache (both local and Redis)
    Multi,
}

impl Default for CacheMode {
    fn default() -> Self {
        Self::Multi
    }
}

/// Multilevel cache configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultilevelConfig {
    /// Cache mode
    pub mode: CacheMode,
    /// Whether to write through to local cache on Redis writes
    pub write_through: bool,
    /// Whether to update local cache on Redis reads
    pub read_through: bool,
    /// Whether to enable circuit breaker for Redis
    pub enable_circuit_breaker: bool,
    /// Number of consecutive Redis failures before triggering circuit breaker
    pub failure_threshold: u32,
    /// Time window in seconds for failure counting
    pub failure_window_secs: u64,
    /// Time in seconds before attempting to reset circuit breaker
    pub reset_timeout_secs: u64,
}

impl Default for MultilevelConfig {
    fn default() -> Self {
        Self {
            mode: CacheMode::Multi,
            write_through: true,
            read_through: true,
            enable_circuit_breaker: true,
            failure_threshold: 5,
            failure_window_secs: 60,
            reset_timeout_secs: 300,
        }
    }
}