Learn

VISUAL GUIDE · SCALING & CACHING

Where a cache helps (and where it lies)

Step 8 of 9: Purge after the write

STEP 8 / 9ORIGINAL SKETCH
GET /abc123get, set on missread alias302 Locationedit targetpurgeBrowserRedirect serviceAlias cacheTTL 60 s2. purgedAlias storesource of truth1. write new targetOwner ormoderator
A browser asks a redirect service for a short link; the service checks a cache, falls back to the alias store on a miss, checks a disabled list, and a link owner or moderator can edit the store, purge the cache, or disable a link.
8 / 9
  1. No cache
  2. Add a cache
  3. Cache hit
  4. Cache miss
  5. Link changes
  6. Stale hit
  7. TTL bounds it
  8. Purge
  9. Deny-list

STEP 8 OF 9 · PURGE

Purge after the write

To shrink the window, the edit flow also sends a purge (an explicit delete) for /abc123 to the cache. The next request misses and reads the new target.

Order matters. Write the store first, then purge. If you purge first, a request can arrive in between, miss, read the old row and put the old target straight back.

Even in the right order there is a rare race: a request that read the old row just before the write can finish its cache fill just after the purge. And purges are messages, so they can get lost. Keep the TTL as the safety net for both.

Why it matters. Invalidation makes changes fast in the normal case; the TTL keeps the worst case bounded when invalidation fails.