CacheKit Docs

High-performance cache policies and supporting data structures.

View the Project on GitHub OxidizeLabs/cachekit

ARC (Adaptive Replacement Cache)

Feature: policy-arc

Status

Implemented in src/policy/arc.rs

Goal

Adapt between recency and frequency automatically, without fixed partition tuning.

Core Idea

Maintain four lists:

ARC maintains a target parameter p that controls the balance between T1 and T2. Hits in ghost lists adjust p:

Core Data Structures

Production ARC uses:

Key Operations (High Level)

Get Operation

Replacement Step

Chooses victim from T1 vs T2 depending on p and where the last hit occurred:

Adaptation

The parameter p is adjusted based on ghost hits:

This adaptation mechanism allows ARC to automatically favor recency or frequency depending on the workload’s characteristics.

Complexity & Overhead

Example Usage

use cachekit::policy::arc::ARCCore;
use cachekit::traits::CoreCache;

// Create ARC cache with 100 entry capacity
let mut cache = ARCCore::new(100);

// Insert items (go to T1 - recent list)
cache.insert("page1", "content1");
cache.insert("page2", "content2");

// First access promotes to T2 (frequent list)
assert_eq!(cache.get(&"page1"), Some(&"content1"));

// Second access keeps in T2 (MRU position)
assert_eq!(cache.get(&"page1"), Some(&"content1"));

// Check list sizes
println!("T1 len: {}, T2 len: {}", cache.t1_len(), cache.t2_len());
println!("Adaptation parameter p: {}", cache.p_value());

When To Use

When NOT To Use

Performance Characteristics

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

Implementation Notes

References