cachekit
High-performance cache policies and tiered caching primitives for Rust systems with optional metrics and benchmarks.
Overview
CacheKit is a Rust library that provides:
- High-performance cache replacement policies (e.g., FIFO, LRU, LRU-K).
- Tiered caching primitives to build layered caching strategies.
- Optional metrics and benchmark harnesses.
- A modular API suitable for embedding in systems where control over caching behavior is critical.
This crate is designed for systems programming, microservices, and performance-critical applications.
Features
- Policy implementations optimized for performance and predictability.
- Backends that support both in-memory and composite cache strategies.
- Optional integration with metrics collectors (e.g., Prometheus/metrics crates).
- Benchmarks to compare policy performance under real-world workloads.
- Idiomatic Rust API with
no_stdcompatibility where appropriate.
Installation
Add cachekit as a dependency in your Cargo.toml:
[]
= { = "https://github.com/OxidizeLabs/cachekit" }
Quick Start
Using the Builder (Recommended)
The CacheBuilder provides a unified API for creating caches with any eviction policy:
use ;
Available Policies
use ;
// FIFO - First In, First Out
let fifo = new.;
// LRU - Least Recently Used
let lru = new.;
// LRU-K - Scan-resistant LRU (K=2 is common)
let lru_k = new.;
// LFU - Least Frequently Used (bucket-based, O(1))
let lfu = new.;
// HeapLFU - Least Frequently Used (heap-based, O(log n))
let heap_lfu = new.;
// 2Q - Two-Queue with configurable probation fraction
let two_q = new.;
Policy Selection Guide
| Policy | Best For | Eviction Basis |
|---|---|---|
| FIFO | Simple, predictable workloads | Insertion order |
| LRU | Temporal locality | Recency |
| LRU-K | Scan-resistant workloads | K-th access time |
| LFU | Stable access patterns | Frequency (O(1)) |
| HeapLFU | Large caches, frequent evictions | Frequency (O(log n)) |
| 2Q | Mixed workloads | Two-queue promotion |
Direct Policy Access
For advanced use cases requiring policy-specific operations, use the underlying implementations directly:
use Arc;
use LruCore;
use ;