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/// Interop mode (interop/v1): cross-SDK cache keys and plain-MessagePack values.
28pub mod interop;
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/// Intent-based cache presets (`CacheKit::minimal`, `::production`, `::encrypted`, `::io`).
39mod intents;
40
41/// Client-side AES-256-GCM encryption with HKDF key derivation.
42#[cfg(feature = "encryption")]
43pub mod encryption;
44
45/// In-process L1 cache backed by [`moka`] with per-entry TTL.
46#[cfg(feature = "l1")]
47pub mod l1;
48
49// Re-exports
50pub use client::{CacheKit, CacheKitBuilder, SharedBackend};
51pub use config::CachekitConfig;
52pub use error::{BackendError, BackendErrorKind, CachekitError};
53
54#[cfg(feature = "encryption")]
55pub use client::SecureCache;
56#[cfg(feature = "encryption")]
57pub use encryption::EncryptionLayer;
58
59#[cfg(feature = "macros")]
60pub use cachekit_macros::cachekit;
61
62/// Convenient glob import for the most common types.
63pub mod prelude {
64    pub use crate::{
65        BackendError, BackendErrorKind, CacheKit, CacheKitBuilder, CachekitConfig, CachekitError,
66    };
67
68    #[cfg(feature = "encryption")]
69    pub use crate::{EncryptionLayer, SecureCache};
70
71    #[cfg(feature = "macros")]
72    pub use crate::cachekit;
73}