In plain words
Cache invalidation is how you make sure a cached copy is replaced when the real data changes, by expiring it, deleting it on write or changing its key, so users don't see yesterday's price.
Where you see it
Harbor caches plan prices in Redis for an hour to spare the database. Marketing drops Pro from $20 to $16, and for the next hour some visitors see $20 on the pricing page while checkout charges $16.
What goes wrong
- Writing the new value into the cache instead of deleting it
Two updates racing can leave the older value in the cache after the newer one reached the database. Deleting the key on write lets the next read fetch the truth.
- A stampede when a busy key expires
When the cached pricing data expires, hundreds of requests miss at the same moment and all query the database. Let one request refill the key while the others serve the old value, and add random jitter to expiry times.
- Forgetting the other copies
Deleting the Redis key doesn't touch the CDN, the framework's page cache or the browser, which each keep their own copy for their own time. List every layer that holds the data and what clears each one.
What to tell your agent
Quick check
Sign in to earn +10 XP for itHarbor deletes a plan's Redis key after every price change, yet the pricing page still shows the old price for 10 minutes afterwards. Where do you look?