Skip to main content

cachekit/
lib.rs

1//! CacheKit — production-ready caching for Rust.
2//!
3//! Supports cachekit.io SaaS, Redis, Memcached, local File, and Cloudflare
4//! Workers backends. Zero-knowledge encryption via AES-256-GCM with HKDF key
5//! derivation.
6
7// Production code lints — these only fire in src/, not tests/
8#![warn(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
9#![warn(missing_docs)]
10
11// Mutually exclusive feature guards
12#[cfg(all(feature = "workers", feature = "redis"))]
13compile_error!(
14    "features `workers` and `redis` are mutually exclusive — Workers runtime cannot use fred"
15);
16
17#[cfg(all(feature = "workers", feature = "l1"))]
18compile_error!("features `workers` and `l1` are mutually exclusive — moka requires std threads unavailable in wasm32");
19
20#[cfg(all(feature = "workers", feature = "memcached"))]
21compile_error!("features `workers` and `memcached` are mutually exclusive — Workers runtime has no TCP sockets");
22
23#[cfg(all(feature = "workers", feature = "file"))]
24compile_error!(
25    "features `workers` and `file` are mutually exclusive — Workers runtime has no filesystem"
26);
27
28/// Pluggable cache backend trait and implementations (CachekitIO, Redis,
29/// Memcached, File, Workers).
30pub mod backend;
31/// High-level cache client with dual-layer (L1/L2) support.
32pub mod client;
33/// Configuration types and environment variable parsing.
34pub mod config;
35/// Error types for cache operations and backend communication.
36pub mod error;
37/// Interop mode (interop/v1): cross-SDK cache keys and plain-MessagePack values.
38pub mod interop;
39/// L1 cache hit-rate metrics for CachekitIO request headers.
40pub mod metrics;
41/// Serialization and deserialization of cached values via MessagePack.
42pub mod serializer;
43/// SDK session tracking (session ID and start timestamp).
44pub mod session;
45/// SSRF-safe URL validation for CachekitIO endpoints.
46pub mod url_validator;
47
48/// Intent-based cache presets (`CacheKit::minimal`, `::production`, `::encrypted`, `::io`).
49mod intents;
50
51/// Client-side AES-256-GCM encryption with HKDF key derivation.
52#[cfg(feature = "encryption")]
53pub mod encryption;
54
55/// In-process L1 cache backed by [`moka`] with per-entry TTL.
56#[cfg(feature = "l1")]
57pub mod l1;
58
59// Re-exports
60pub use client::{CacheKit, CacheKitBuilder, SharedBackend};
61pub use config::CachekitConfig;
62pub use error::{BackendError, BackendErrorKind, CachekitError};
63
64#[cfg(feature = "encryption")]
65pub use client::SecureCache;
66#[cfg(feature = "encryption")]
67pub use encryption::EncryptionLayer;
68
69#[cfg(feature = "macros")]
70pub use cachekit_macros::cachekit;
71
72/// Convenient glob import for the most common types.
73pub mod prelude {
74    pub use crate::{
75        BackendError, BackendErrorKind, CacheKit, CacheKitBuilder, CachekitConfig, CachekitError,
76    };
77
78    #[cfg(feature = "encryption")]
79    pub use crate::{EncryptionLayer, SecureCache};
80
81    #[cfg(feature = "macros")]
82    pub use crate::cachekit;
83}