ASP. NET page output Cache

Source: Internet
Author: User

I sorted out the ASP. NET cache mechanism in MSDN.

Typically, applications can store frequently accessed data and data that requires a large amount of processing time to be created in the memory, thus improving performance. For example, if an application uses complex logic to process a large amount of data and then returns the data as a report that is frequently accessed by the user, it is more efficient to avoid re-creating a report when the user requests data each time. Similarly, if an application contains a page that processes complex data but does not need to be updated frequently, re-creating the page on the server upon each request will result in inefficiency.

In these cases, ASP. NET uses two basic caching mechanisms to improve application performance. The first mechanism is application caching, which allows you to cache generated data, such as DataSet or custom Report Business Objects. The second mechanism is the page output cache, which saves the page processing output and reuses the saved output when the user requests the page again, instead of processing the page again.
Application Cache

The application cache provides a programming method that stores any data in the memory through key/value pairs. The application cache status is similar to that of the application. However, unlike the application state, the data in the application cache is easy to lose, that is, the data is not stored in the memory throughout the application lifecycle. The advantage of using the application cache is that ASP. NET manages the cache, which removes the items in the cache when the items expire, are invalid, or the memory is insufficient. You can also configure the application cache to notify the application when an item is removed. For more information, see cache application data.

The application cache mode is used to determine whether the specified item exists in the cache when you access it. If yes, it is used. If this item does not exist, you can re-create it and put it back into the cache. This mode ensures that the latest data is always in the cache.

For more information, see How to: retrieve the value of a cache item.

Page output cache stores the processed ASP. NET page content in the memory. This mechanism allows ASP. NET to send page responses to the client without having to go through the page processing lifecycle again. The page output cache is particularly useful for pages that do not change frequently but require a large amount of processing to be created. For example, if you create a webpage with large traffic to display data that does not need to be updated frequently, the page output cache can greatly improve the performance of the page. You can configure page cache for each page, or create a cache configuration file in the Web. config file. With the cache configuration file, you can use these settings on multiple pages by defining the cache settings only once.

The page output cache provides two types of page cache models: full page cache and partial page cache. The full-page cache allows you to store all the page content in the memory and use it to complete client requests. Partial-page cache allows you to cache part of the page content, while other parts are dynamic content. For more information, see the ASP. NET page.

Partial-page cache can be replaced by control cache and cache. The control cache is also called the segment cache. This method allows information to be contained in a user control, and the user control is marked as cacheable to cache part of the page output. This method caches specific content on a page and does not cache the entire page. Therefore, you need to recreate the entire page each time. For example, if you want to create a page that displays a large amount of dynamic content such as stock information, some of which are static content such as weekly summary), you can place the static content in the user control, and allow caching of the content.

The cache replacement is the opposite to the control cache. This method caches the entire page, but the sections in the page are dynamic. For example, if you want to create a page that is static within a specified period of time, you can set the entire page to cache. If you add a Label control that displays the user name to the page, the Label content remains unchanged for each page refresh and each user, the name of the user who requested the page before caching the page is always displayed. However, with the cache replacement mechanism, you can configure the page to be cached, but mark individual parts of the page as non-cached. In this case, you can add Label controls to the non-cacheable section to dynamically create these controls for each user and each page request. For more information, see some sections on the cache ASP. NET page.

  1. Analysis on ASP. NET Web Security
  2. Session State of ASP. NET
  3. Analysis on the attribute ASP. NET of IsPostBack
  4. ASP. NET architecture and security mechanism
  5. Overview ASP. NET Crystal Reports

Related Article

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.