Skip to content

Commit e50f00c

Browse files
committed
Add new cache policies and enhance documentation
- Introduced MFU, LIFO, Random, MRU, and SLRU cache policies with corresponding implementations and eviction strategies. - Added example programs for each new policy to demonstrate usage. - Implemented invariant validation for cache policies to ensure internal consistency. - Updated documentation for all new policies, including architecture and usage patterns. - Enhanced README to reflect the addition of new policies and their availability. - Removed legacy performance tests for LFU, LRU-K, and LRU policies to streamline testing efforts.
1 parent 4a9c2b5 commit e50f00c

2 files changed

Lines changed: 71 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@ All notable changes to cachekit will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
- MFU (Most Frequently Used) cache policy (`MfuCache`) with frequency-based eviction that keeps most frequently accessed items.
12+
- LIFO (Last In, First Out) cache policy (`LifoCache`) with stack-based eviction.
13+
- Random eviction cache policy (`RandomCache`) with XorShift64 RNG for unpredictable eviction patterns.
14+
- MRU (Most Recently Used) cache policy (`MruCache`) with recency-based eviction of most recently accessed items.
15+
- Segmented LRU (SLRU) cache policy (`SlruCache`) with probationary and protected segments for scan resistance.
16+
- Example programs: `basic_mfu.rs`, `basic_lifo.rs`, `basic_random.rs`, `basic_mru.rs`, `basic_slru.rs`.
17+
- Invariant validation for cache policies to ensure internal consistency during operations.
18+
- Regression test for FIFO behavior in `FrequencyBuckets`.
19+
20+
### Documentation
21+
- Complete documentation for MFU policy (`docs/policies/mfu.md`) with architecture and usage patterns.
22+
- Complete documentation for LIFO policy (`docs/policies/lifo.md`) with stack semantics and use cases.
23+
- Complete documentation for Random eviction policy (`docs/policies/random.md`) with RNG strategy.
24+
- Complete documentation for MRU policy (`docs/policies/mru.md`) with recency-based eviction.
25+
- Complete documentation for SLRU policy (`docs/policies/slru.md`) with segment management and promotion strategies.
26+
- Updated examples in cache policy documentation to use integer keys and values for consistency.
27+
28+
### Changed
29+
- Random eviction policy now uses XorShift64 for RNG state management, improving performance and predictability.
30+
- Updated dependencies and enhanced benchmarking structure for better performance analysis.
31+
32+
### Removed
33+
- Legacy performance tests for LFU, LRU-K, and LRU policies (consolidated into newer test suite).
34+
835
## [0.2.0-alpha] - 2026-01-19
936

1037
### Added

README.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ cachekit = { git = "https://github.com/OxidizeLabs/cachekit" }
4242

4343
CacheKit is a Rust library that provides:
4444

45-
- High-performance cache replacement policies (e.g., **FIFO**, **LRU**, **LRU-K**).
45+
- High-performance cache replacement policies (e.g., **FIFO**, **LRU**, **LRU-K**, **S3-FIFO**, **SLRU**, **2Q**, and more).
4646
- Supporting data structures and policy primitives for building caches.
4747
- Optional metrics and benchmark harnesses.
4848
- A modular API suitable for embedding in systems where control over caching behavior is critical.
@@ -85,6 +85,8 @@ fn main() {
8585

8686
### Available Policies
8787

88+
#### Builder API Policies
89+
8890
```rust
8991
use cachekit::builder::{CacheBuilder, CachePolicy};
9092

@@ -116,17 +118,49 @@ let s3_fifo = CacheBuilder::new(100).build::<u64, String>(
116118
);
117119
```
118120

121+
#### Additional Policies (Direct Access)
122+
123+
These policies are available through direct instantiation but not yet exposed in the builder API:
124+
125+
```rust
126+
use cachekit::policy::lifo::LifoCore;
127+
use cachekit::policy::mfu::MfuCore;
128+
use cachekit::policy::mru::MruCore;
129+
use cachekit::policy::random::RandomCore;
130+
use cachekit::policy::slru::SlruCore;
131+
132+
// LIFO - Last In, First Out (stack-like eviction)
133+
let mut lifo: LifoCore<u64, String> = LifoCore::new(100);
134+
135+
// MFU - Most Frequently Used (evicts hot items)
136+
let mut mfu: MfuCore<u64, String> = MfuCore::with_bucket_hint(100, 32);
137+
138+
// MRU - Most Recently Used (evicts recently accessed)
139+
let mut mru: MruCore<u64, String> = MruCore::new(100);
140+
141+
// Random - Uniform random eviction
142+
let mut random: RandomCore<u64, String> = RandomCore::new(100);
143+
144+
// SLRU - Segmented LRU with probationary/protected segments
145+
let mut slru: SlruCore<u64, String> = SlruCore::new(100, 0.25);
146+
```
147+
119148
### Policy Selection Guide
120149

121-
| Policy | Best For | Eviction Basis |
122-
|---------|----------|----------------|
123-
| FIFO | Simple, predictable workloads | Insertion order |
124-
| LRU | Temporal locality | Recency |
125-
| LRU-K | Scan-resistant workloads | K-th access time |
126-
| LFU | Stable access patterns | Frequency (O(1)) |
127-
| HeapLFU | Large caches, frequent evictions | Frequency (O(log n)) |
128-
| 2Q | Mixed workloads | Two-queue promotion |
129-
| S3-FIFO | Scan-heavy workloads | FIFO + ghost history |
150+
| Policy | Best For | Eviction Basis | Builder API |
151+
|---------|----------|----------------|-------------|
152+
| FIFO | Simple, predictable workloads | Insertion order ||
153+
| LRU | Temporal locality | Recency ||
154+
| LRU-K | Scan-resistant workloads | K-th access time ||
155+
| LFU | Stable access patterns | Frequency (O(1)) ||
156+
| HeapLFU | Large caches, frequent evictions | Frequency (O(log n)) ||
157+
| 2Q | Mixed workloads | Two-queue promotion ||
158+
| S3-FIFO | Scan-heavy workloads | FIFO + ghost history ||
159+
| LIFO | Stack-like caching | Reverse insertion order | - |
160+
| MFU | Inverse frequency | Highest frequency | - |
161+
| MRU | Anti-recency patterns | Most recent access | - |
162+
| Random | Baseline/uniform distribution | Random selection | - |
163+
| SLRU | Scan resistance | Segmented LRU | - |
130164

131165
See [Choosing a policy](docs/guides/choosing-a-policy.md) for benchmark-driven guidance.
132166

0 commit comments

Comments
 (0)