Skip to main content

Module composition

Module composition 

Source
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

§Write Policies

§Refill Policy

§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§

CompositionBackend
A backend that composes two cache backends into a layered caching system.

Enums§

CompositionError
Error type for composition backend operations.