Concept Flow - Cache invalidation strategies
Client requests data
Check cache for data
End
This flow shows how a system checks cache before fetching fresh data and how cache invalidation triggers update the cache.
GET /data if cache.has(data): return cache.get(data) else: fresh = fetch_from_server() cache.set(data, fresh) return fresh
| Step | Action | Cache State | Data Returned | Cache Invalidation Trigger |
|---|---|---|---|---|
| 1 | Client requests /data | Empty | None | None |
| 2 | Check cache for data | Empty | None | None |
| 3 | Cache miss, fetch fresh data | Empty | None | None |
| 4 | Store fresh data in cache | Data stored | None | None |
| 5 | Return fresh data to client | Data stored | Fresh data | None |
| 6 | Later client requests /data | Data stored | None | None |
| 7 | Check cache for data | Data stored | Cached data | None |
| 8 | Return cached data to client | Data stored | Cached data | None |
| 9 | Cache expiry time reached | Data stored | None | Time-based expiry |
| 10 | Invalidate cache | Empty | None | Cache cleared |
| 11 | Next client request /data | Empty | None | None |
| 12 | Cache miss, fetch fresh data | Empty | None | None |
| 13 | Store fresh data in cache | Data stored | None | None |
| 14 | Return fresh data to client | Data stored | Fresh data | None |
| Variable | Start | After Step 4 | After Step 8 | After Step 10 | After Step 13 | Final |
|---|---|---|---|---|---|---|
| cache | Empty | Data stored | Data stored | Empty | Data stored | Data stored |
| data returned | None | None | Cached data | None | None | Fresh data |
Cache Invalidation Strategies: - Check cache before fetching data - If cache miss, fetch fresh data and update cache - Invalidate cache by: * Time-based expiry * Manual purge * Event-based triggers - Keeps data fresh and reduces server load