简体   繁体   中英

Cache data received from AJAX

I am developing client part of web application. So i have some controls like grid, image gallery and so on. All data i receive throught AJAX requests. Is it good idea to cache already received data? i'm afraid that if grid have thousands rows it could eat users RAM and my application will be slow. What is good practice?

The HTTP Protocol has already a system to cache data.

It's not necessary to use a cache in javascript for data received from an ajax request, just you need to use correctly the HTTP Cache.

For explanation of Cache-Control HTTP directives, see the specification at http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 .

It's a good idea to cache your data if the data is stable for some time: from what you describe, i'd recommend it.

However your concern with memory is a good one so you must have a cache that is limited in size, can expire and allows you easy manipulation; have a look at jCache (just one example) to see what would be recommended. You can use it as a starting point to create your own solution. This article shows how to add caching to a submit call in ajax

Well to provide the answer you are looking for would need much more information, but in short, you need to do some calculations, and then think about what matters to your users.

First - you need to quantify the amount of memory involved here:

How much memory does 1 row take up?

How big can the grid be?

Secondly, given the figure above you need to consider your users needs:

Is the extra memory requirement from (1) going to be a problem? 500Mb is ok for a modern machine, but quite an ask for an older machine. If you're exposing your app within a corporate infrastructure, they will be able to tell you their machine specs.

Does it give you enough of a performance boost to be worthwhile? How long does the data take to gather? How long to transmit/receive. You can reduce the latter by use of compression (easy in IIS7). If it's the former, you should explore server-side caching, and general code/database refactoring.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM