asp.net 2.0 cache (theoretical article)

Source: Internet
Author: User
Tags server memory stock prices
Asp.net| Cache

ASP.net 2.0 provides some new technical features for lifting program performance, in which caching technology is a very important feature that provides a very good local data caching mechanism that can be easily customized as data mitigation, thereby effectively improving data access performance.

Caching has a disadvantage that is not easily overcome, that is, the problem of data expiration. Most typically, if you cache the contents of a database table into server memory, the Web application is likely to display outdated, inaccurate data when records in the database table change. For some types of data, even if the displayed information expires, the impact is not very large. However, it is unacceptable for data that is more stringent in real time requirements, such as stock prices, auction bids, and so on.

ASP.net 2.0 supports the following types of caching

Page Output Caching

Page output caching is the simplest caching mechanism that saves the entire ASP.net page content in server memory. When the user requests the page, the system outputs the relevant data from memory until the cached data expires. In this process, the cached content is sent directly to the user without having to go through the page process lifecycle again. Typically, page output caching is especially useful for pages that contain content that does not need to be modified frequently, but that requires a lot of processing to compile. It is important to note that the page output cache saves the entire contents of the page in memory and is used to complete the client request.

Page Partial Caching

Page partial caching refers to parts of the output cache page, rather than caching the entire page content. There are two mechanisms for implementing page partial caching: One is to place the portion of the page that needs to be cached in a user control (. ascx file) and to set caching for the user control (the page that contains the user control can be set or not set to cache). This is what is commonly called the "control cache." The essence of setting the control cache is to cache the user control for configuration. Mainly includes the following 3 methods: One is to use the @ OutputCache directive to set caching for the user control declaratively, and the second is to use the PartialCachingAttribute class in the code-behind file to set the user control cache Third, use the Controlcachepolicy class to programmatically specify user control cache settings. In addition, there is a method called "cache replacement." This method, in contrast to the control cache, sets a portion of the page to not be cached, so that, while the entire page is cached, the page is processed again when it is requested again, which is not set to the cached content.

Application Data Caching

Application data caching provides a programmatic way to store arbitrary data in memory through key/value pairs. Using application caching is similar to using application state. However, unlike application state, the data in the application data cache is volatile, meaning that the data is not stored in memory throughout the application life cycle. The advantage of the application data cache is that the asp.net manages the cache, which removes items from the cache when items expire, is invalid, or is out of memory, and can configure application caching to notify the application when an item is removed.

Cache dependencies

Net 2.0 introduces custom cache dependencies, especially the SqlCacheDependency features based on Ms-sql server, so that we can avoid the "data expiration" problem, which notifies the cache based on the changes in the corresponding data in the database. and remove those outdated data caching features also have their own shortcomings. For example, the displayed content may not be the most recent and accurate, so you must set up an appropriate caching policy. For example, caching increases the complexity of the system and makes it difficult to test and debug, so it is recommended that you develop and test your application without caching, and then enable caching options during the performance tuning phase.



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.