mx-cache 0.1.0

Shared cache utilities (local + Redis) for MultiversX Rust services.
Documentation
//! Shared cache utilities for `MultiversX` Rust services.
//!
//! Provides a simple async-friendly `Cache` trait plus Redis and local
//! implementations with TTL semantics.
//!
//! # Re-exports
//!
//! This crate re-exports the `redis` crate for use by dependent crates,
//! allowing them to access low-level Redis functionality without adding
//! a direct dependency.

use std::time::Duration;

// Re-export redis crate for dependent crates to use
pub use ::redis;

pub trait Cache: Send + Sync {
    fn set_nx_px(
        &self,
        key: &[u8],
        value: &[u8],
        ttl: Duration,
    ) -> impl Future<Output = anyhow::Result<bool>> + Send;

    fn set(
        &self,
        key: &[u8],
        value: &[u8],
        ttl: Duration,
    ) -> impl Future<Output = anyhow::Result<()>> + Send;

    fn get(&self, key: &[u8]) -> impl Future<Output = anyhow::Result<Option<Vec<u8>>>> + Send;

    fn del(&self, key: &[u8]) -> impl Future<Output = anyhow::Result<()>> + Send;
}

mod local;
mod redis_cache;
mod utils;

pub use local::LocalCache;
pub use redis_cache::RedisCache;
pub use utils::namespaced;
pub mod set;
pub use set::RedisSet;

/// Mock implementations for testing without external dependencies.
pub mod mock;

#[cfg(test)]
mod tests;