All games

Cache Eviction Lab

Predict cache hits and misses as requests flow through an LRU cache, then experiment with TTL behavior and stale data tradeoffs.

Concept
Cache hits, misses, LRU, TTL, and stale data
Difficulty
Beginner
Play time
5-8 minutes
Path
Data & Performance
practice/cache-eviction-lab Cache prediction score

Play, get feedback, save local progress, and optionally submit a leaderboard score.

Concept explanation

Caching is a tradeoff between speed, capacity, and freshness. This lab makes those moving parts visible through a small request sequence.

Your local progress

0 XP 0 games played 0 completed

Progress, review history, and best scores are stored in this browser with localStorage.

Open full progress dashboard

Playable game area

Use the controls below. Feedback appears immediately, and final scores are stored locally.

Leaderboard

Top 10 submitted scores. No account required.

Loading leaderboard...

    Finish the game to load your latest local score.

    Learning objectives

    • Predict cache hits and misses from a request sequence.
    • Visualize LRU eviction as cache capacity fills.
    • Understand how TTL changes freshness and hit rate.

    How to play

    1. Review the next request key and current cache slots.
    2. Predict whether the request will be a hit or miss.
    3. Watch the cache update and compare your prediction to LRU behavior.

    Scoring

    • Correct hit/miss predictions add points.
    • Streaks reward careful state tracking.
    • TTL mode is slightly harder and can produce different outcomes.

    Backend concept notes

    A cache hit avoids slower work, such as database reads or remote API calls. A miss repopulates the cache and may evict another item.

    LRU evicts the least recently used item. TTL expires items based on age, which can protect freshness but reduce hit rate.

    Common mistakes

    • Thinking cache capacity is unlimited.
    • Forgetting that reading an item updates its recency in LRU.
    • Using long TTLs for data that must be fresh.

    FAQ

    Short answers for how this game fits backend interview and study practice.

    Why do caches return stale data?

    Cached values can outlive the source update unless they are invalidated or expire through TTL.

    Is a higher hit rate always better?

    Not always. High hit rate is useful, but correctness and freshness matter too.