kegani 0.1.0

A developer-friendly, ergonomic, production-ready Rust web framework
Documentation
//! Cache decorators for Kegani
//!
//! Provides helper functions for automatic caching.

use crate::cache::RedisCache;

/// Cache invalidation helper
pub struct CacheInvalidator {
    cache: RedisCache,
    patterns: Vec<String>,
}

impl CacheInvalidator {
    /// Create a new invalidator
    pub fn new(cache: RedisCache) -> Self {
        Self {
            cache,
            patterns: Vec::new(),
        }
    }

    /// Add a pattern to invalidate
    pub fn add_pattern(mut self, pattern: &str) -> Self {
        self.patterns.push(pattern.to_string());
        self
    }

    /// Invalidate all matching patterns
    pub async fn invalidate(&self) -> Result<u64, crate::cache::client::CacheError> {
        let mut total = 0u64;
        for pattern in &self.patterns {
            let deleted = self.cache.delete_pattern(pattern).await?;
            total += deleted;
        }
        Ok(total)
    }
}