Skip to main content

hexz_core/cache/
mod.rs

1//! In-memory caching for decompressed blocks and index pages.
2//!
3//! This module implements the caching layer that sits between the storage backend
4//! and the read API, dramatically reducing decompression overhead and I/O for
5//! repeated access patterns.
6//!
7//! # Architecture
8//!
9//! The cache system consists of three components:
10//!
11//! ```text
12//! ┌──────────────┐
13//! │  File  │ Read API
14//! └──────┬───────┘
15//!        │
16//! ┌──────┴────────────────────┐
17//! │  Cache Layer              │
18//! │  ┌────────────────────┐   │
19//! │  │ LRU Block Cache    │   │ Sharded, thread-safe
20//! │  ├────────────────────┤   │
21//! │  │ Prefetcher         │   │ Sequential detection
22//! │  ├────────────────────┤   │
23//! │  │ Eviction Policy    │   │ LRU or none
24//! │  └────────────────────┘   │
25//! └───────────┬───────────────┘
26//!             │
27//! ┌───────────┴──────────┐
28//! │  Storage Backend     │ FileBackend, S3, HTTP, etc.
29//! └──────────────────────┘
30//! ```
31//!
32//! # Performance Impact
33//!
34//! | Metric | No Cache | With Cache (512MB) |
35//! |--------|----------|--------------------|
36//! | Sequential read (1st pass) | 600 MB/s | 600 MB/s |
37//! | Sequential read (2nd pass) | 600 MB/s | **2500 MB/s** |
38//! | Random IOPS (warm) | 2000 | **15000** |
39//! | Decompression CPU | 100% | **5%** (cached) |
40//!
41//! # Cache Configuration
42//!
43//! Default cache size is **512 MB** (configurable via `Config`):
44//! - Sufficient for ~8K blocks @ 64KB each
45//! - Covers typical VM working set (database, OS cache)
46//! - Can be tuned based on available RAM
47//!
48//! # Submodules
49//!
50//! - [`lru`]: Sharded LRU cache implementation
51//! - [`prefetch`]: Sequential pattern detection and read-ahead
52
53/// Background and anticipatory prefetch logic.
54///
55/// Implements heuristics for reading future blocks ahead of demand to hide
56/// storage latency for sequential and patterned workloads.
57pub mod prefetch;
58
59/// LRU cache implementation for decompressed data and index pages.
60///
61/// Maintains sharded LRU structures used by `File` for efficient
62/// concurrent access and cache eviction.
63pub mod lru;