DEV Community

Discussion on: Client-side caching with Angular

Collapse
 
mauro_codes profile image
Mauro Garcia

If you want to ignore the cached version, you just need to call the remove method of the cache service. Then, the http-client will return null after trying to get the data from cache and will fetch new data from the server

Collapse
 
kdfemi profile image
MiniSoda

I don’t mean ignoring the cached version, i feel the user should be served the cached version first the a request to the server should also be sent instead of the cached version only served without making any request to the serve. I don’t know if it an efficient approach thou

Thread Thread
 
mauro_codes profile image
Mauro Garcia

I think that what you say may be or may not be the best solution based on your requirements. Example: maybe you are not working with critical information, or information is not updated regularly... Or maybe you have a slow server and you want to optimize resource usage...in those cases I think it's totally OK to prevent requests for a couple of minutes.

But if you need to always get the newest, what you are saying is perfectly valid. You can show the cached data first and, under the hood, fetch for new data and show a refresh button when there is new data to display

Thread Thread
 
kdfemi profile image
MiniSoda

This is awesome, i will always put this in mind