简体   繁体   中英

Data Caching strategities fort ASP.NET MVC Web Application

I'm building a MVC application which has a heavy client side scripting using Knockout,JQuery and JSON etc.

This web application has a lot of charts for business data insights and analysis purpose. JQuery Ajax calls the MVC WebAPI which returns JSON and using Jquery and Knockout the chart is redendered.

Could someone please suggest what are good practices of caching a large number of data on MVC web application?

Any help will be much appreciated.

The way I understand your question is twofold:

  1. What data should I cache?
  2. And how should I cache it?

What data should I cache?

That, of course, depends. Most of the time you want to cache data that are frequently used but rarely changes or is expensive to compute. Sometimes you need to cache one or more objects and at other times you'll need to cache the whole page. Again, this decision comes down your particular business needs.

How should I cache it?

There are a few ways of doing this and they will depend on what you're trying to cache.

Caching objects

If availability of data on multiple severs is not an issue, you could use built-in cache object to store data for a certain period of time. See this thread for a discussion on how to cache items in ASP.NET. However, if you have a web farm with non-sticky requests, then you may think about setting up a memcached server to achieve very performant, scalable caching.

Caching output/pages

The easiest way to cache these is to add OutputCache attribute to the controller actions that require it. Take a look at the link for some nice uses (like caching different versions of a page based on a parameter).

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