ASP.NET 2.0 provides some new technical features for improving program performance. Caching technology is a very important feature. It provides a very good local data caching mechanism that can be easily customized. Thus, the performance of data access can be effectively improved.
Caching has a shortcoming that is not easy to overcome, and that is the problem of data expiration. The most typical situation is that if the data content in the database table is cached in the server memory, the web application is likely to display outdated and inaccurate data when the records in the database table change. For some types of data, even if the displayed information is out of date, the impact will not be significant. However, for data with strict real-time requirements, such as stock prices, auction bids and other information, it is unacceptable to display data that is slightly out of date.
ASP.NET 2.0 supports the following types of cached page output cache. Page output cache is the simplest caching mechanism. This mechanism saves the entire ASP.NET page content in the 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 processing life cycle again. Typically, page output caching is particularly useful for pages that contain content that does not need to be modified frequently, but requires a lot of processing to compile to completion. Readers should note that the page output cache stores all the content of the page in memory and is used to complete client requests.
Page partial cache
Partial page caching means that the output caches certain parts of the page instead of caching the entire page content. There are two mechanisms to implement partial page caching: one is to place the part of the page that needs to be cached in a user control (.ascx file), and set the caching function for the user control (the page containing the user control may or may not set caching) . This is commonly referred to as "control caching". The essence of setting the control cache is to configure the cache of the user control. It mainly includes the following three methods: one is to use the @OutputCache directive to declaratively set the cache function for the user control; the other is to use the PartialCachingAttribute class in the code-behind file to set the user control cache; the third is to use the ControlCachePolicy class to programmatically specify the user control cache set up. Alternatively, there is a method called "replace after cache". This method is just the opposite of control caching. It sets a certain part of the page to not be cached. Therefore, although the entire page is cached, when the page is requested again, the content that is not set to be cached will be reprocessed.
Application Data Cache The Application Data Cache provides a programmatic way to store arbitrary data in memory using key/value pairs. Using the application cache is similar to using application state. However, unlike application state, the data in the application data cache is volatile, that is, the data is not stored in memory for the entire application lifetime. The advantage of the application data cache is that ASP.NET manages the cache, which removes items from the cache when they are expired, invalid, or out of memory. The application cache can also be configured to notify the application when an item is removed.
cache dependency
The custom cache dependencies introduced in Net 2.0, especially the SqlCacheDependency feature based on MS-SQL Server, allow us to avoid the "data expiration" problem. It can notify the cache and remove those that have expired based on changes in the corresponding data in the database.
data
caching feature also has its own shortcomings. For example, the content displayed may not be the latest and most accurate, and for this reason, appropriate caching policies must be set. As another example, caching increases the complexity of the system and makes it difficult to test and debug, so it is recommended to develop and test the application without caching and then enable the caching option during the performance optimization phase.