Module cache

Module cache 

Source
Expand description

Advanced caching utilities with TTL and memory management.

This module provides caching structures with time-to-live (TTL) support, automatic eviction, and memory management for efficient data caching.

§Examples

use chie_core::cache::TtlCache;
use std::time::Duration;

let mut cache = TtlCache::new(100, Duration::from_secs(60));

// Insert with TTL
cache.insert("key1".to_string(), "value1".to_string());

// Retrieve (returns cloned value)
assert_eq!(cache.get(&"key1".to_string()), Some("value1".to_string()));

// Entry expires after TTL
std::thread::sleep(Duration::from_millis(100));
// Still valid within TTL
assert!(cache.get(&"key1".to_string()).is_some());

Structs§

CacheStats
Cache statistics.
SizedCache
Cache with size-based eviction (for byte-counted values).
TieredCache
Two-level cache with L1 (fast, small) and L2 (larger).
TtlCache
Time-to-live cache with automatic expiration.