Expand description
Multi-tier caching by combining two backends.
This backend implements a layered caching strategy where:
- L1 (first layer): Fast local cache (e.g., Moka)
- L2 (second layer): Distributed cache (e.g., Redis)
§Policies
Behavior is controlled by configurable policies. See the policy module for details.
§Read Policies
policy::SequentialReadPolicy- Try L1, then L2 on miss (default)policy::RaceReadPolicy- Race both layers, return first hitpolicy::ParallelReadPolicy- Query both in parallel, prefer fresher
§Write Policies
policy::SequentialWritePolicy- Write L1, then L2policy::OptimisticParallelWritePolicy- Write both in parallel (default)policy::RaceWritePolicy- Race both, background the slower
§Refill Policy
policy::RefillPolicy::Always- Populate L1 after L2 hitpolicy::RefillPolicy::Never- Skip L1 population (default)
§Example
ⓘ
use hitbox_backend::composition::{Compose, CompositionPolicy};
use hitbox_backend::composition::policy::{RaceReadPolicy, RefillPolicy};
// Default policies
let cache = moka.compose(redis, offload);
// Custom policies
let policy = CompositionPolicy::new()
.read(RaceReadPolicy::new())
.refill(RefillPolicy::Always);
let cache = moka.compose(redis, offload).with_policy(policy);Re-exports§
pub use compose::Compose;pub use policy::CompositionPolicy;
Modules§
- compose
- Trait for composing backends into layered cache hierarchies.
- policy
- Policy traits and implementations for controlling composition backend behavior.
Structs§
- Composition
Backend - A backend that composes two cache backends into a layered caching system.
Enums§
- Composition
Error - Error type for composition backend operations.