Cache pages in an ASP. NET MVC application using donut Caching and donut Hole caching

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.