If an application has client side caching, and data changes on server side, then how does client comes to know about it so that it can invalidate the cache?
-
Clients are stateless so may be you can associate a key with your data and check if that key's related data is still present on server or not on some client event. Or use something like websocket or webrtc. – Saurabh bhatia Jan 29 '22 at 14:05
-
But that means a backend call, which defeats the very purpose of caching..isn't? – Mandroid Jan 29 '22 at 14:08
1 Answers
If server send "Cache-Control: max-age=100" on response header after first action to get data from server then client save response data on local cache store.
If client send same request in about 100 seconds then response retrieved from local cache store and request dont send to server.
When pass over 100 seconds and send same request again to server, cache data will have been invalidate on local. Thus request arrive to server. If server recognize the request and decide to not modified on the source then do nothing and return response that's status is 304 (not modified).
Seeing this status, the client renews the validity period of the expired data and all requests they sent within 100 seconds are retrieved from the cache again.
This flow has client cache invalidate mechanism.

- 216
- 3
- 11