Skip to main content

Module tiered_cache

Module tiered_cache 

Source
Expand description

Multi-tier cache (L1 memory → L2 memory → disk).

Each tier has an independent EvictionPolicy and a byte-level capacity. On a miss the implementation searches lower tiers in order; on a hit in a lower tier the entry is promoted to L1.

§New in 0.1.2

  • File-backed disk tierTierConfig::disk_path enables a real file-backed tier backed by a directory on disk. Each cache key maps to a file inside that directory; reads and writes use std::fs.
  • Adaptive promotion thresholds — each tier now tracks access frequency per key. A hit in tier i only promotes to tier i-1 when the key’s frequency exceeds the tier’s promotion_threshold. This prevents scan pollution from one-shot accesses filling the hot tier.
  • Entry compression — tiers with compress: true store LZ4-style run-length encoding (pure Rust, no external deps) so that L2+ tiers occupy less memory / disk space.

§New in 0.1.8 Wave 13

  • P² adaptive promotion — the promotion threshold can be auto-tuned using a P² quantile estimator (Jain & Chlamtac 1985) that tracks the 75th-percentile of per-key access frequencies. Enable via TieredCacheBuilder::enable_adaptive_promotion(true).
  • Arena allocation — when use_arena is enabled, tier entry bytes are stored in a BumpArena (bump allocator) so the HashMap holds cheap (offset, len) handles instead of owned Vec<u8>.

Structs§

BumpArena
A simple bump allocator for byte-slice entries.
P2QuantileEstimator
Online running estimator for an arbitrary quantile using the P² algorithm.
TierConfig
Configuration for one tier.
TierStats
Per-tier statistics snapshot.
TieredCache
A multi-tier cache where each tier has its own TierConfig.
TieredCacheStats
Aggregate statistics snapshot for the whole TieredCache.

Enums§

EvictionPolicy
Eviction strategy for a single cache tier.