zenmanage 1.0.0

Official Zenmanage feature flags SDK for Rust
Documentation
use std::{future::Future, pin::Pin, sync::Arc, time::Duration};

use crate::errors::Result;

/// A cache that persists to a directory.
pub mod filesystem;
/// A cache held in process memory.
pub mod memory;
/// A cache that keeps nothing.
pub mod null;

/// The future returned by a [`CacheBackend`].
pub type CacheFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T>> + Send + 'a>>;

/// Cache backend abstraction used for rules payload caching.
pub trait CacheBackend: Send + Sync {
    /// Returns the value stored under `key`, or `None` if there is none or it has expired.
    fn get<'a>(&'a self, key: &'a str) -> CacheFuture<'a, Option<String>>;
    /// Stores `value` under `key` for `ttl`.
    fn set<'a>(&'a self, key: &'a str, value: String, ttl: Duration) -> CacheFuture<'a, ()>;
}

/// A cache backend shared between managers.
pub type SharedCache = Arc<dyn CacheBackend>;