Skip to main content

CacheBackend

Trait CacheBackend 

Source
pub trait CacheBackend: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn get(&self, key: &str) -> Result<Option<CacheEntry>, String>;
    fn set(
        &self,
        key: &str,
        entry: CacheEntry,
        ttl_ms: Option<u64>,
    ) -> Result<(), String>;
    fn delete(&self, key: &str) -> Result<bool, String>;
    fn invalidate_tag(&self, tag: &str) -> Result<u32, String>;
    fn invalidate_path(&self, pattern: &str) -> Result<u32, String>;

    // Provided method
    fn is_healthy(&self) -> bool { ... }
}
Expand description

Alternative cache storage backend (e.g., Redis, S3, Cloudflare KV).

Replaces or wraps the built-in LRU cache for ISR entries. Only one backend can be active at a time.

Required Methods§

Source

fn name(&self) -> &str

Unique identifier (e.g., "redis", "cloudflare-kv").

Source

fn get(&self, key: &str) -> Result<Option<CacheEntry>, String>

Look up a cached entry. Returns Ok(None) on miss.

Source

fn set( &self, key: &str, entry: CacheEntry, ttl_ms: Option<u64>, ) -> Result<(), String>

Store an entry with optional TTL in milliseconds.

Source

fn delete(&self, key: &str) -> Result<bool, String>

Delete a single entry by key. Returns whether it existed.

Source

fn invalidate_tag(&self, tag: &str) -> Result<u32, String>

Invalidate all entries tagged with tag. Returns count invalidated.

Source

fn invalidate_path(&self, pattern: &str) -> Result<u32, String>

Invalidate entries matching a path glob. Returns count invalidated.

Provided Methods§

Source

fn is_healthy(&self) -> bool

Health check. Default returns true.

Implementors§