shreyansh
shreyansh

Reputation: 1687

How much data should we cache in memory in single page applications?

Lets say I have a very big complex nested object which I am caching in memory

single page application caching

Now assume that I want to use different subsets of object in different modules/components of our application and for that I may need to do lot of mapping operations(using loops by matching the id's etc) on UI.

I was thinking in other way around that instead of doing so much operations on UI to extract the relevant data why don't I use a simple API with having id parameter to fetch the relevant information if its not taking much time to get the data from backend.

url =  some/url/{id}

So is it worth to cache more complex nested objects if we cant use its subset simply by its properties obj[prop] and need to do lot of calculations on UI (looping etc) which actually is more time consuming than getting the data from rest API ?

Any help/explanation will be appreciated !!!

Thanks

Upvotes: 5

Views: 2923

Answers (1)

sreejithsdev
sreejithsdev

Reputation: 1210

Caching too much data in memory is not a good idea. It will affect your application performance. Causes performance degradation in a system having less memory. theoretically cache memory is for keeping less amount of data. The maximum support size is 2GB. I think chrome is also supported up to that limit. For keeping data of big size in client-side never use memory cache instead you should use client-side database/datastore. It uses disk space instead of memory. There are number of web technologies that store data on the client-side like

  • Indexed Database
  • Web SQL
  • LocalStorage
  • Cookies

Depending upon the client application framework it can be decided.

By default browser uses 10% of disk space for these data stores. We also have option to increase that size.

Upvotes: 0

Related Questions