CacheKit Docs

High-performance cache policies and supporting data structures.

View the Project on GitHub OxidizeLabs/cachekit

CAR (Clock with Adaptive Replacement)

Status

Implemented in src/policy/car.rs

Goal

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.

Core Idea

Replace ARC’s LRU lists with Clock structures plus ghost history:

Core Data Structures

Key Operations (High Level)

Get Operation

Insert Operation

Replacement Step

Loop until one entry is evicted:

Adaptation

Same as ARC: ghost hit in ghost_recent increases target_recent_size; ghost hit in ghost_frequent decreases it.

Complexity & Overhead

Example Usage

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());

When To Use

When NOT To Use

Performance Characteristics

Metric Value
Get O(1)
Insert O(1) amortized
Remove O(1)
Space O(n) + ghost keys
Scan res High
Adaptivity Self-tuning

Implementation Notes

References