Donut Hole Caching is the inverse of Donut caching means while caching the entire page it cached only a small part of the page(the donut hole).
When to use Donut Hole caching...
Suppose, you have a web application in which ProductCategory is shown on each and every pages so it makes sense to render all of the categories just once and cache the resulting HTML by using Donut Hole Caching.
Donut Hole caching is very useful in the scenarios where most of the elements in your page are dynamic except the few sections that rarely change, or changed based on a request parameter. Asp.Net MVC has great support for Donut Hole caching through the use of Child Actions
- [OutputCache(Duration=60)]
- public ActionResult CategoriesList()
- {
- // Get categories list from the database and
- // pass it to the child view
- ViewBag.Categories = Model.GetCategories();
- return View();
- }
View with Donut Hole Caching
Now call the above action method "CategoriesList" from the parent view as shown below:
- <h1>MVC Donut Hole Caching Demo</h1>
- <div>@Html.Action("CategoriesList")</div>
- <!-- Rest of the page with non cacheable content goes here -->
No comments:
Post a Comment