Donut caching is the best way to cache an entire page in addition to some content, and before it appears, we use "Output caching" to cache the entire page.
When to use Donut Caching
Suppose you have an application that has a page like "home" that always presents the user with the same or very little change in addition to the user's login name. At this point you may need to cache most of the content. Join you using "output cache" and apply a VaryByParam userid to do cache processing, the entire page will generate a cache for each access user, but this is not a good way to cache when we have a large number of login users.
To solve this problem, donut caching proposes to cache only one copy for all users and contains a small amount of dynamic content, a small part of the dynamic content like a hole in a doughnut.
Donut Caching's NuGet package
Before you use donut caching, you need to use the NuGet installation package in Visual Studio, which is typically typed directly into the command installation:
Install-package mvcdonutcaching
Once the installation is complete, you can control the cache by adding Donutoutputcache tags to the action or controller, and most outputcache tags can be used in Donutoutputcache.
Public classHomecontroller:controller {[Donutoutputcache (Duration= -, varybyparam="username")] PublicActionResult Index (stringusername) { returnView (); } [Donutoutputcache (Duration= -)] PublicActionResult About () {Viewbag.message="Your Application description page."; returnView (); } PublicActionResult Contact () {Viewbag.message="Your Contact page."; returnView (); } }
Donut Hole Caching
Donut Hole caching and donut caching just the opposite, it is used to cache a small portion of the page.
When to use Donut Hole Caching
Suppose you have an application that needs to display a list of products on each page, then caching a list of products in HTML is very much needed, donut Hole caching is designed to handle this situation, ASP. MVC can support child requests by setting Childactiononly tags
[Childactiononly] [Donutoutputcache (Duration=)] Public actionresult categorylist () { return View (categoryservice.getcategories); }
Original address: http://www.dotnet-tricks.com/Tutorial/mvc/ODJa210113-Donut-Caching-and-Donut-Hole-Caching-with-Asp.Net-MVC-4.html
Cache pages in an ASP. NET MVC application using donut Caching and donut Hole caching