sisa-caching 0.3.2

Composable caching for Rust: an in-memory store, a Redis-family store, and a hybrid that keeps local copies coherent across nodes
Documentation
//! Caching for Rust services: an in-memory store, a store on Redis, Valkey, Dragonfly or Garnet,
//! and a hybrid that keeps a local copy on each node and drops it when another node writes. Every
//! store has the same calls (`get`, `set`, `get_or_set`, `remove`, `remove_prefix` and `clear`)
//! through the [`CacheStore`] trait, so switching stores changes one line.
//!
//! No store is on by default; turn on the ones you use:
//!
//! | Feature | Adds |
//! | --- | --- |
//! | `memory` | `InMemoryCacheStore` |
//! | `redis` | `RedisCacheStore`, and the `redis` crate it is built on |
//! | `hybrid` | `HybridCacheStore`; turns on `memory` and `redis` |
//! | `tls-rustls` | `rediss://` URLs through rustls; turns on `redis` |
//! | `tls-native-tls` | `rediss://` URLs through the system's TLS library; turns on `redis` |
//!
//! ```
//! # #[cfg(feature = "memory")]
//! # #[tokio::main(flavor = "current_thread")]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use sisa_caching::{CacheStore, InMemoryCacheStore};
//!
//! // It drops expired entries every 60 seconds by itself.
//! let cache = InMemoryCacheStore::new("app")?;
//!
//! let name = cache
//!     .get_or_set("user:v1:42", async || Ok::<_, std::io::Error>("Ada".to_string()), None)
//!     .await?;
//!
//! assert_eq!(name, "Ada");
//! # Ok(())
//! # }
//! # #[cfg(not(feature = "memory"))]
//! # fn main() {}
//! ```
//!
//! A hybrid on one Redis server, which applies the other nodes' invalidations by itself:
//!
//! ```no_run
//! # #[cfg(feature = "hybrid")]
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! use sisa_caching::{CacheStore, HybridCacheSettings, HybridCacheStore};
//!
//! let settings = HybridCacheSettings::default();
//! let cache = HybridCacheStore::connect("app", "redis://127.0.0.1:6379", &settings).await?;
//!
//! cache.set("user:v1:42", "Ada".to_string(), None).await?;
//! # Ok(())
//! # }
//! ```
//!
//! Each part is also its own crate (`sisa-caching-core`, `-memory`, `-redis`, `-hybrid`), whose
//! docs cover the details: key and entry formats, Cluster and Sentinel, the backplane, and the
//! metrics. An application that uses one store can depend on the core crate and that store's
//! crate instead. `CacheStore` is sealed, so these stores are its only implementations; the Redis
//! store runs on any `RedisConnection`.

#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(unsafe_code)]
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]

pub use sisa_caching_core::{
    CacheEntry, CacheError, CacheKey, CacheOptions, CacheSettings, CacheStore, CacheValue,
    KeyPrefix,
    clock::{Clock, SystemClock},
};

#[cfg(feature = "memory")]
pub use sisa_caching_memory::{InMemoryCacheSettings, InMemoryCacheStore, MemorySettings};

#[cfg(feature = "redis")]
pub use sisa_caching_redis::{
    RedisCacheError, RedisCacheSettings, RedisCacheStore, RedisConnection, RedisSettings,
    SentinelConnection, connection_config, redis,
};

#[cfg(feature = "hybrid")]
pub use sisa_caching_hybrid::{
    BackplaneWorkerSettings, HybridCacheError, HybridCacheSettings, HybridCacheStore,
    LocalSettings, NodeId, RedisBackplane, RedisHybridCacheStore,
};