Course contentsShow
← System Design
Lesson 145 of 1,9194. Caching StrategiesFree lesson

What Are Cache Eviction Policies?

Understanding when and why caches must remove entries to make room for new data as memory fills up.

What Are Cache Eviction Policies?

You'll learn: Why caches must automatically remove old entries and what happens when memory fills up.

The Fundamental Problem

Caches have limited memory. Unlike databases that can store vast amounts of data on disk, a cache (like Redis or Memcached) operates primarily in fast but expensive RAM. As your application adds more entries to the cache, eventually you'll run out of space.

Cache eviction policies are the rules that determine which entries to remove when the cache is full and new data needs to be stored.

Why We Need Eviction Policies

Imagine a library with only 100 shelf spaces. As new popular books arrive, librarians must decide which older books to remove to make room. Without a clear policy, the library becomes chaotic—either rejecting all new books or randomly discarding valuable ones.

Similarly, without an eviction policy, your cache would either:

  • Reject new entries (wasting cache opportunities)
  • Run out of memory and crash
  • Remove entries unpredictably, hurting performance

When Eviction Happens

Eviction triggers when:

  1. Memory limit reached: The cache has used its allocated RAM
  2. New entry requested: Application tries to cache additional data
  3. No expired entries: TTL-based removal isn't enough to free space

The eviction policy automatically selects which existing entry to discard, making room for the new one—all without application intervention.

Key Takeaway: Cache eviction policies are automated rules for removing entries when memory is full, ensuring caches continue serving fresh, valuable data without running out of space or crashing.