Skip to content
BENIBIX Learn

Cache Invalidation

Development⚙️ Compilers & RuntimesPerformance

Also known as Invalidate Cache, Cache Busting, Stale Cache

Clearing an old copy once the real data changes. Then no one sees old data.

Think of it like

Think of it like a menu board in a cafe. When a price changes, someone must wipe the old one off.

Example

Jack changes a product's price from 20 to 25 euros. His code deletes that product from the cache, so the next visitor sees 25 euros, not 20.

Why it matters

A cache that is never cleared will, sooner or later, show wrong data. That can cost money and trust.

Definition

Cache invalidation is clearing a cached copy once the real data changes. If it is not done, people see old data, like a price that has gone up. One common way is to let copies expire after a set time. Another is to delete them when the data is saved. Getting the timing right is hard. A well-known saying calls it one of the two hard things in computer science, along with naming things.

Common mistake

Setting a long time to expire and then forgetting it. Choose it by asking how old the data may be.

Key takeaways

  1. 1
    Data changed. The copy must go.
  2. 2
    Expire or delete. By time, or on save.
  3. 3
    Decide how old. Is too old.