CacheKit Docs

High-performance cache policies and supporting data structures.

View the Project on GitHub OxidizeLabs/cachekit

LRU-K

Goal

Improve scan resistance by evicting based on the K-th most recent access time, rather than last access time.

Core Idea

Track the last K access timestamps for each key.

In cachekit, LRU-K is implemented in src/policy/lru_k.rs with segmented tracking for < K and >= K entries.

Core Data Structures

Common LRU-K:

For efficient victim selection, many implementations maintain:

Operations

touch/get(key)

pop_lru_k()

Eviction priority:

  1. any entry with < K accesses (cold): evict oldest by first access time
  2. otherwise: evict the entry with the oldest K-distance (K-th most recent access is oldest)

Complexity & Overhead

References