CacheKit Docs

High-performance cache policies and supporting data structures.

View the Project on GitHub OxidizeLabs/cachekit

Cache Replacement Policies

This document summarizes common cache replacement (eviction) policies, their tradeoffs, and when to use (or avoid) each. It’s written as a practical companion to docs/design.md.

Implementation notes live in docs/policies/README.md.

Terminology used below:

How To Choose (Quick Guidance)

Pick based on workload first:

If you can only implement one “general purpose” policy for mixed workloads, ARC-style adaptivity or LRU-K/2Q-style scan resistance usually beats plain LRU, at the cost of more metadata and complexity.

Policy Catalog (Summaries)

OPT / MIN (Belady’s Optimal)

Idea: evict the item whose next use is farthest in the future.

Random

Idea: evict a uniformly random resident item.

FIFO (First-In, First-Out)

Idea: evict the oldest inserted item.

LIFO / FILO (Last-In, First-Out)

Idea: evict the most recently inserted item.

LRU (Least Recently Used)

Idea: evict the item not accessed for the longest time.

MRU (Most Recently Used)

Idea: evict the most recently accessed item.

Second-Chance / Clock

Idea: approximate LRU using a circular list and a referenced bit; give items a “second chance”.

NRU (Not Recently Used)

Idea: evict an item whose “referenced” bit is not set; bits are periodically cleared (epochs).

LFU (Least Frequently Used)

Idea: evict the item with the smallest access count.

MFU (Most Frequently Used)

Idea: evict the most frequently used item.

Aging / Decayed LFU (LFU with time decay)

Idea: combine frequency with time so old counts lose influence (e.g., periodic halving, exponential decay).

LRU-K

Idea: evict based on the K-th most recent access time (e.g., K=2 tracks the 2nd most recent touch).

2Q

Idea: use two queues: a short “probation” FIFO for new items and a main LRU for items that are accessed again.

SLRU (Segmented LRU)

Idea: split LRU into segments (e.g., probationary + protected); promotion requires reuse.

ARC (Adaptive Replacement Cache)

Idea: adaptively balances recency vs frequency using two LRU lists plus “ghost” history lists to tune itself.

CAR (Clock with Adaptive Replacement)

Idea: ARC-like adaptivity but with Clock structures to reduce overhead.

LIRS (Low Inter-reference Recency Set)

Idea: use inter-reference recency (distance between repeated touches) to classify and protect frequently reused items.

CLOCK-Pro

Idea: Clock-based policy that differentiates hot/cold pages and tracks recent history to handle scans better than Clock.

Size/Cost-Aware Policies (GDS / GDSF family)

Idea: evict based on a “value” score that accounts for retrieval cost and/or object size (common in web caches).

TTL / Time-Based Expiration (Not a Replacement Policy)

Idea: entries expire after a time-to-live, regardless of recency/frequency.

Practical Tradeoffs (What Changes In Real Systems)

When To Use / Not Use (Rules Of Thumb)

Reference Material