Computer Science

LFU Resident-Frequency Cache

Compare resident-frequency and recency eviction decisions on the same access stream.

By Riano · Published · Updated · Report a correction

LFU Resident-Frequency Cache Theory

The Least Frequently Used (LFU) cache policy tracks the frequency of access for each resident item in the cache. When the cache reaches capacity and a new item must be inserted, the item with the minimum frequency count is evicted.

Worked Example

Let's trace a Mixed stream A, B, A, C, A, B, D through an LFU cache with capacity 2.

  1. A (Miss): Cache = [A:1].
  2. B (Miss): Cache = [A:1, B:1].
  3. A (Hit): Cache = [A:2, B:1].
  4. C (Miss): Minimum count is B (1). Evict B. Cache = [A:2, C:1].
  5. A (Hit): Cache = [A:3, C:1].
  6. B (Miss): Minimum count is C (1). Evict C. Cache = [A:3, B:1].
  7. D (Miss): Minimum count is B (1). Evict B. Cache = [A:3, D:1].

After this stream, the resident keys are A,D with counts A:3, D:1. Hits = 2, Misses = 5, Evictions = 3.

Interactive Experiment

You can test different streams and compare policies in the interactive module.

  1. Set the Stream to Mixed.
  2. Set the Capacity to 2.
  3. Set the Policy to LFU and observe the Hits and Evictions.
  4. Change the Policy to LRU and compare how recency affects the resident keys compared to frequency.

Limitations

True LFU maintains counts only while an item is resident in the cache; an evicted item loses its count and restarts at 1 if re-inserted. This small-scale exact LFU differs from probabilistic counters or lifetime frequency tracking systems like those in Redis. Furthermore, in LFU ties (multiple items having the same lowest frequency count) need a tie-breaking rule; here, we use Least Recently Used access time, then alphabetical order.

References

For more context on caching strategies and processor memory architecture, see the MIT Computer System Architecture lecture notes:https://csg.csail.mit.edu/6.5900/Lectures/L03handout.pdf

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive LFU Resident-Frequency Cache module.

Try LFU Resident-Frequency Cache on Riano →

More in Computer Science