System Design
7. Caching ArchitectureAnimated
Time-To-Live (TTL)
The lifetime of a cache entry.
The idea
A TTL counts down from the moment of storage. When it hits zero the entry is gone.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- 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
- 1Set a TTL on store
- 2Entry is served until it expires
- 3It is deleted
- 4Next request reloads
Where it is used
Almost all caches and DNS.
Watch out for
Too short loses benefit; too long serves stale data.