Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much memory is too much when caching objects in the Browser?

I'm fairly inexperienced in frontend engineering, so I apologize if this comes off as naive or too broad.

My app fetches 4k JSON objects via AJAX. To prevent repeated HTTP requests, the returned JSON is cached in an object within the global window scope. Are there any best practices regarding this sort of thing?

I realize that a reasonable limit on the size of the cache will depend on the the browser, the OS, hardware, and other factors. I'm on the look out for degraded UI responsiveness.

Are there any good rules of thumb, though?

like image 561
Ben Avatar asked Mar 02 '12 15:03

Ben


People also ask

What is the limit of cache memory?

The size of this memory ranges from 1 MB to 8MB.

How big should cache size be?

Memory caches smaller than 1 MB are nonfunctional, and the performance of caches smaller than 5 MB is usually unsatisfactory. Suitable upper limits are similar to those for disk caches but are probably determined more by the demands on memory from other sources on the machine (number of users and processes).

What happens if the cache memory is full?

This begs the question of what happens if the cache memory is already full. The answer is that some of the contents of the cache memory has to be “evicted” to make room for the new information that needs to be written there.

What does too much cache do?

Caches are generally small stores of temporary memory. If they get too large, they can cause performance to degrade. They also can consume memory that other applications might need, negatively impacting application performance.


1 Answers

This strongly depends on your task and large percent of users you would like to have.

If you have nice 3D game, then even 500MB would be ok (but not all for JSON cache)

Modern browsers require 50-100MB of memory from the start. Therefore 50MB for all your javascript objects should be ok in most cases and I suppose 50MB is large enough for any simple(twitter)/average(gmail) web app.

Also, RAM costs 5-7$ per GB now.

Keep in mind, that, 4k of stringified JSON will turn into 10-50kb in objects and even in string form will take almost 8k (If you use utf-8 for http transfer) since js engines uses UTF-16 for internal string representation.

like image 156
kirilloid Avatar answered Oct 29 '22 16:10

kirilloid