Skip to main content

sockudo_core/
cache.rs

1use crate::error::Result;
2use async_trait::async_trait;
3use std::time::Duration;
4
5// Cache Manager Interface trait
6#[async_trait]
7pub trait CacheManager: Send + Sync {
8    /// Check if the given key exists in cache
9    async fn has(&self, key: &str) -> Result<bool>;
10
11    /// Get a key from the cache
12    /// Returns None if cache does not exist
13    async fn get(&self, key: &str) -> Result<Option<String>>;
14
15    /// Set or overwrite the value in the cache
16    async fn set(&self, key: &str, value: &str, ttl_seconds: u64) -> Result<()>;
17
18    /// Remove a key from the cache
19    async fn remove(&self, key: &str) -> Result<()>;
20
21    /// Disconnect the manager's made connections
22    async fn disconnect(&self) -> Result<()>;
23
24    /// Health check for the cache manager
25    async fn check_health(&self) -> Result<()> {
26        // Default implementation - always healthy for memory/no-op caches
27        Ok(())
28    }
29
30    async fn ttl(&self, key: &str) -> Result<Option<Duration>>;
31}