☕ Cache Eviction — Lessons from a Small Café

Imagine running a cozy café with a tiny pastry shelf. You can only keep a few items at a time, and when the shelf is full, something has to go. The real question: which pastry gets kicked off to make room for the new one?

That’s exactly what caches do…


This content originally appeared on DEV Community and was authored by Sumana

Imagine running a cozy café with a tiny pastry shelf. You can only keep a few items at a time, and when the shelf is full, something has to go. The real question: which pastry gets kicked off to make room for the new one?

That’s exactly what caches do in software. The shelf is your RAM, pastries are data, and the “kick-off” rules are called cache eviction policies. Let’s see how each works — café style.

FIFO — First In, First Out

Kick out the oldest item first.

Everyday café analogy: The cinnamon bun that’s been sitting on the shelf longest gets tossed to make space for fresh pastries.

Why it works: What if that cinnamon bun is still a customer favorite? FIFO doesn’t care — it’s gone.

Where it's used: Simple and predictable, FIFO works in queues, streaming buffers, and systems where order matters more than popularity.

LFU — Least Frequently Used

Kick out the least popular item.

Everyday café analogy: The chocolate cake nobody ever orders gets removed, while cheesecake that flies off the shelf stays.

Why it works: A pastry that was trendy last month might still hog space today, even though no one buys it anymore.

Where it's used: LFU is great for CDNs, recommendation engines, and image caches — places where popularity beats freshness.
👉 Try it here: LeetCode LFU Cache

LRU — Least Recently Used

Kick out the item that hasn’t been touched in the longest time.

Everyday café analogy: That croissant sitting untouched for days gets tossed, while the one someone grabbed just yesterday stays.

Why it works: Sometimes recency isn’t everything — a customer-favorite pastry could still get removed if it hasn’t sold lately.

Where it's used: LRU is the most common default. It powers browser caches, Redis eviction, OS page replacement, and session storage.
👉 Try it here: LeetCode LRU Cache

MRU — Most Recently Used

Kick out the newest item you just used.

Everyday café analogy: You whip up a fresh green matcha latte, take one sip, and toss it. Strange rule, but sometimes it works.

Why it works: You risk losing the freshest, most relevant data.

Where it's used: Rarely used, but handy in niches like database cursors or workloads where older data is more valuable.

The Café Lesson

Your café shelf — like a cache — can only hold so much. Different rules give you different trade-offs:

  • FIFO → Oldest cinnamon bun goes.
  • LFU → Least-loved chocolate cake goes.
  • LRU → Stale croissant goes.
  • MRU → Fresh green matcha latte goes.


This content originally appeared on DEV Community and was authored by Sumana


Print Share Comment Cite Upload Translate Updates
APA

Sumana | Sciencx (2025-09-26T15:15:00+00:00) ☕ Cache Eviction — Lessons from a Small Café. Retrieved from https://www.scien.cx/2025/09/26/%e2%98%95-cache-eviction-lessons-from-a-small-cafe/

MLA
" » ☕ Cache Eviction — Lessons from a Small Café." Sumana | Sciencx - Friday September 26, 2025, https://www.scien.cx/2025/09/26/%e2%98%95-cache-eviction-lessons-from-a-small-cafe/
HARVARD
Sumana | Sciencx Friday September 26, 2025 » ☕ Cache Eviction — Lessons from a Small Café., viewed ,<https://www.scien.cx/2025/09/26/%e2%98%95-cache-eviction-lessons-from-a-small-cafe/>
VANCOUVER
Sumana | Sciencx - » ☕ Cache Eviction — Lessons from a Small Café. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/26/%e2%98%95-cache-eviction-lessons-from-a-small-cafe/
CHICAGO
" » ☕ Cache Eviction — Lessons from a Small Café." Sumana | Sciencx - Accessed . https://www.scien.cx/2025/09/26/%e2%98%95-cache-eviction-lessons-from-a-small-cafe/
IEEE
" » ☕ Cache Eviction — Lessons from a Small Café." Sumana | Sciencx [Online]. Available: https://www.scien.cx/2025/09/26/%e2%98%95-cache-eviction-lessons-from-a-small-cafe/. [Accessed: ]
rf:citation
» ☕ Cache Eviction — Lessons from a Small Café | Sumana | Sciencx | https://www.scien.cx/2025/09/26/%e2%98%95-cache-eviction-lessons-from-a-small-cafe/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.