Skip to content
StackDecode
System Design
7. Caching ArchitectureAnimated

Cache Expiration

Entries are dropped after a set time or condition.

The idea

Expiration bounds how stale data can be.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

request streamABFBFADADADFAADAACBDAFcache (4 slots)Ain at 1MISS A is fetched from the databasehit rate 0% (0 of 1)
  • hit
  • current request

A is missing: fetch it from the database and store it.

step:
1
hits:
0
1/22

Eviction policy: oldest inserted.

Step by step

  1. 1Store with an expiry
  2. 2Serve while valid
  3. 3Remove when expired
  4. 4Reload on next access

Where it is used

Bounding staleness.

Watch out for

Many keys expiring together cause a stampede. Add jitter.

Related