CacheKit Docs

High-performance cache policies and supporting data structures.

View the Project on GitHub OxidizeLabs/cachekit

MRU (Most Recently Used)

Feature: policy-mru

Goal

Evict the most recently accessed entry.

Core Idea

MRU is the opposite of LRU:

This is useful for specific cyclic or sequential access patterns where the most recently accessed item is unlikely to be accessed again soon.

Core Data Structures

In cachekit, src/policy/mru.rs uses:

Operations

get(key)

insert(key, value)

Eviction Logic

Complexity & Overhead

When to Use

MRU is only beneficial for specific access patterns:

Use MRU when:

Avoid MRU when:

Examples

When MRU Works Well

Cyclic Pattern (database index scans):
  Access: Index A → Index B → Index C → Index A → Index B → Index C → ...

  MRU behavior:
    - Each access moves item to MRU (head)
    - When cache full, evict most recent (which won't be needed for 2 more accesses)
    - LRU would be worse here (would evict item about to be reused)

When MRU Works Poorly

Temporal Locality (typical workload):
  Access: page1, page1, page1, page2, page3, page1, page1, ...

  MRU behavior:
    - page1 accessed frequently → moves to MRU → gets evicted!
    - Terrible performance
    - LRU would be much better

Implementation in cachekit

If you already have an LRU structure (recency-ordered list):

So MRU is “LRU, but evict from head instead of tail”.

Comparison with Other Policies

Policy Eviction Point Best For Risk
LRU Tail (LRU) Temporal locality Scan pollution
MRU Head (MRU) Cyclic/sequential patterns Evicts frequently used items
SLRU Probation LRU Scan resistance Tuning required
FIFO Oldest Predictable order No adaptation

Safety / Invariants (Rust)

Uses intrusive pointers (NonNull<Node<_>>):

References