Invalidating a Service Cache After a Data Change
A data change can make a cached representation stale. Invalidation identifies which keys or versions should no longer serve as current.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a moved article
An edit can change an article detail and the subject list showing its title. Invalidating the detail alone leaves the list view stale. See collection and detail page links.
Check the order of events
An invalidation sent before the write is visible can allow the old value to be cached again. Verify the chosen commit and invalidation boundary. Committing state before rendering provides related reasoning.[1]
Order cache changes relative to durable storage
If an application invalidates a cache before a database write commits, another request can reload the old value in the gap. An invalidation tied to committed changes can reduce this race. Other policies use versions or bounded lifetimes. See cache result validity.
t1 clear cached v1
t2 another request reloads visible v1
t3 commit v2
Cache still holds v1 unless design addresses the gap
Define the allowed period of inconsistency
Some systems can tolerate stale values until expiry, while others require read-your-writes. Test attempted write rollback and one successful write with a concurrent reader. Verify which version was served.