Module tiered_cache

Module tiered_cache 

Source
Expand description

Multi-level cache hierarchy for optimal performance and cost.

This module implements a multi-tiered caching system with automatic promotion and demotion between levels based on access patterns:

  • L1: Hot data in memory (fastest, smallest)
  • L2: Warm data on SSD (fast, medium)
  • L3: Cold data on HDD (slow, largest)

§Example

use chie_core::tiered_cache::{TieredCache, TieredCacheConfig};
use std::path::PathBuf;

let config = TieredCacheConfig {
    l1_capacity_bytes: 100 * 1024 * 1024,      // 100 MB in memory
    l2_capacity_bytes: 1024 * 1024 * 1024,     // 1 GB on SSD
    l3_capacity_bytes: 10 * 1024 * 1024 * 1024, // 10 GB on HDD
    l2_path: PathBuf::from("/fast-ssd/cache"),
    l3_path: PathBuf::from("/slow-hdd/cache"),
    promotion_threshold: 3,  // Promote after 3 accesses
};

let mut cache = TieredCache::new(config).await?;

// Insert data (starts in L1)
cache.put("key1".to_string(), b"hot data".to_vec()).await?;

// Get data (automatically promotes if accessed frequently)
if let Some(data) = cache.get("key1").await? {
    println!("Found data: {} bytes", data.len());
}

// Get cache statistics
let stats = cache.stats();
println!("L1 hit rate: {:.2}%", stats.l1_hit_rate() * 100.0);

Structs§

TieredCache
Multi-level cache with automatic tiering.
TieredCacheConfig
Configuration for tiered cache.
TieredCacheStats
Statistics for tiered cache.

Enums§

CacheTier
Cache tier levels.
TieredCacheError
Tiered cache error types.