ASP.NET MVC 缓存扩展 - Donut Caching
2014-05-12 16:03 音乐让我说 阅读(609) 评论(0) 收藏 举报
项目介绍
ASP.NET MVC Extensible Donut Caching brings donut caching to ASP.NET MVC 3 and later. The code allows you to cache all of your page apart from one or more Html.Actions which can be executed every request. Perfect for user specific content.
项目地址:https://github.com/moonpyk/mvcdonutcaching
Download
The best way to add donut caching to your MVC project is to use the NuGet package. From within Visual Studio, select Tools | Library Package Manager and then choose either Package Manager Console or Manage NuGet Packages. Via the console, just type install-package MvcDonutCaching and hit return. From the GUI, just search for MvcDonutCaching and click the install button.
Usage
The package adds several overloads to the built-in Html.Action HTML helper. The extra parameter in each overload is named excludeFromParentCache. Set this to true for any action that should not be cached, or should have a different cache duration from the rest of the page.
@Html.Action("Login", "Account", true)
The package also include a DonutOutputCacheAttribute to be used in place of the built-in OutputCacheAttribute. This attribute is typically placed on every controller action that needs be be cached.
You can either specify a fixed duration:
[DonutOutputCache(Duration = "300")] public ActionResult Index() { return View(); }
Or, use a cache profile:
[DonutOutputCache(CacheProfile = "FiveMins")] public ActionResult Index() { return View(); }
If you are using cache profiles, be sure to configure the profiles in the web.config. Add the following within the system.web element:
<caching> <outputCacheSettings> <outputCacheProfiles> <add name="FiveMins" duration="300" varyByParam="*" /> </outputCacheProfiles> </outputCacheSettings> </caching>
You can also configure the output cache to use a custom provider:
<caching> <outputCache defaultProvider="DistributedCacheProvider"> <providers> <add name="DistributedCacheProvider" type="DevTrends.Example.DistributedCacheProvider" /> </providers> </outputCache> </caching>
Note, that a custom provider is not included with this project but you can write one fairly easily by subclassingSystem.Web.Caching.OutputCacheProvider. A number of implementations are also available on the web.
More Information
A comprehensive guide to MVC Extensible Donut Caching is now available on the DevTrends Blog.
谢谢浏览!
作者:音乐让我说(音乐让我说 - 博客园)
出处:http://music.cnblogs.com/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
浙公网安备 33010602011771号