High-performance cache policies and supporting data structures.
Implemented in src/policy/car.rs
ARC-like adaptivity with Clock mechanics to reduce list manipulation overhead. Hits only set a reference bit instead of moving entries in linked lists, improving concurrency and cache-friendliness.
Replace ARC’s LRU lists with Clock structures plus ghost history:
target_recent_size (the adaptation parameter)HashMap<K, usize> for key → slot indexRing (Recent/Frequent)hand_recent, hand_frequent) walking per-ring intrusive circular listsghost_recent, ghost_frequent (keys only) via GhostList<K>referenced = true, return value (no list move)ghost_recent: adapt (increase target_recent_size), evict if needed, insert into Frequent ringghost_frequent: adapt (decrease target_recent_size), evict if needed, insert into Frequent ringLoop until one entry is evicted:
|Recent| > target_recent_size: sweep the Recent ring
ghost_recent, done|Recent| ≤ target_recent_size: sweep the Frequent ring
ghost_frequent, doneSame as ARC: ghost hit in ghost_recent increases target_recent_size;
ghost hit in ghost_frequent decreases it.
use cachekit::policy::car::CARCore;
use cachekit::traits::{CoreCache, ReadOnlyCache};
let mut cache = CARCore::new(100);
cache.insert("page1", "content1");
cache.insert("page2", "content2");
assert_eq!(cache.get(&"page1"), Some(&"content1"));
println!("recent: {}, frequent: {}, target: {}", cache.recent_len(), cache.frequent_len(), cache.target_recent_size());
| Metric | Value |
|---|---|
| Get | O(1) |
| Insert | O(1) amortized |
| Remove | O(1) |
| Space | O(n) + ghost keys |
| Scan res | High |
| Adaptivity | Self-tuning |
capacity eachtarget_recent_size starts at capacity / 2