In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how to use Donut Caching and Donut Hole Caching to cache pages in ASP.NET MVC applications, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Donut Caching is the best way to cache the entire page except part of the content, and before it appeared, we used the "output cache" to cache the entire page.
When to use Donut Caching
Suppose you have an application that has a page like "home page", which always presents the same or little change to the user except the user name to which the user is logged in. At this point you may need to cache most of the content. Add that if you use the "output cache" and apply a VaryByParam UserID for caching, the entire page will generate a cache for each visiting user, but this is not a good way to cache when we have a large number of logged-in users.
To solve this problem, Donut Caching proposes to cache only one copy for all users and contains a small portion of dynamic content, which is like a hole in a doughnut.
Donut Caching's Nuget package
Before using Donut Caching, you need to use the Nuget installation package in Visual studio. Generally, type the command directly to install it:
Install-package MvcDonutCaching
Once installed, you can control the cache by adding DonutOutputCache tags to action or controller, and most OutputCache tags can be used in DonutOutputCache.
Public class HomeController: Controller
{
[DonutOutputCache (Duration = 60 VaryByParam = "username")]
Public ActionResult Index (string username)
{
Return View ()
}
[DonutOutputCache (Duration=60)]
Public ActionResult About ()
{
ViewBag.Message = "Your application description page."
Return View ()
}
Public ActionResult Contact ()
{
ViewBag.Message = "Your contact page."
Return View ()
}
}
Donut Hole Caching
Donut Hole Caching, in contrast to Donut Caching, is used to cache a small portion of a page.
When to use Donut Hole Caching
Suppose you have an application that needs to display a product list on each page, so it is necessary to cache a product list in the form of HTML. Donut Hole Caching is designed to handle this situation. ASP.NET MVC can support sub-requests by setting the ChildActionOnly tag.
[ChildActionOnly]
[DonutOutputCache (Duration=60)]
Public ActionResult CategoryList ()
{
Return View (categoryService.GetCategories)
}
So much for sharing about how to use Donut Caching and Donut Hole Caching to cache pages in ASP.NET MVC applications. I hope the above content can be helpful and learn more. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.