Skip to main content

cachekit/
lib.rs

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