开发者

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

I have a ASP.NET 开发者_如何学GoMVC 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 (e.g 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.

E.g:

[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.

E.g "weighty" database calls should be cached on the web server (e.g "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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜