简体   繁体   中英

How do i do caching the right way in a ASP.NET MVC 3.0 project?

I have a ASP.NET MVC 3.0 project with a MySQL database that going to need caching on to get faster to load for users.

What is your best tip on how to do caching on a ASP.NET MVC project?

If you want server-side caching (eg caching "data"), you should look into .NET 4.0's new ObjectCache .

If you want output cache , you should decorate your action methods with said attribute, much like with Web Forms.

Eg:

[HttpGet]
[OutputCache(Duration = 60*5, VaryByParam("*")] // cache for 5 mins
public ActionResult GetSomethingThatDoesntChangeOften(int someParam, string someOtherParam)
{
   // some code  ...
}

You should use one or both, depending on the situation at hand.

Eg "weighty" database calls should be cached on the web server (eg "data caching").

And HTML that doesn't change often should be cached on the client with output cache.

We use the Caching Application Block from Microsoft

http://msdn.microsoft.com/en-us/library/ff664753(v=pandp.50).aspx

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