Mandroid
Mandroid

Reputation: 7504

How to invalidate client-cache?

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?

Upvotes: 1

Views: 2109

Answers (1)

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.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching

HTTP Cache-Control refresh flow image

Upvotes: 1

Related Questions