DEV Community

Caching Data in frontend

Rishabh Gupta on December 18, 2018

We'll talk about ways you can effectively cache requests sent to backend without fidelling with backend HTTP headers. Coordinating data between st...
Collapse
 
akashkava profile image
Akash Kava

LocalStorage and SessionStorage both are synchronous operations and will block browser on large datasets, you must consider IndexedDb over it, and there are shims available with deprecated browser Sql.

Collapse
 
zeerorg profile image
Rishabh Gupta

Thanks for the comment, I did look into it, but I think that it has a bit more complex api. Also Indexed db is aimed at more complex operations like traditional databases whereas session storage is a bit simpler and can handle cache invalidation with session storage.
I am not saying that it cannot be replaced, Indexed db is still a lot better option than managing state itself, and if blocking the main thread becomes a performance bottleneck then it might be worthwhile to look into it.

Collapse
 
edisonywh profile image
Edison Yap

Cool article! I'm curious to how cache invalidation works though?

Collapse
 
zeerorg profile image
Rishabh Gupta • Edited

Currently only session storage has automatic data clearance where data is removed if a user closes the tab.
If you are using state management framework or passing data around a single page app then as soon as you navigate away from that page your data will be cleared. Both localstorage and indexed db store data for as long as possible.