ASP. NET 2.0 provides some new technical features for improving program performance. The cache technology is a very important feature and provides a very good local data cache mechanism, you can easily customize data to slow down, thus effectively improving the performance of data access.
Cache has a disadvantage that cannot be easily overcome, that is, data expiration. The most typical case is that if the data content in the database table is cached in the server memory, when the records in the database table change, web applications may display expired and inaccurate data. For some types of data, even if the displayed information expires, the impact will not be great. However, for data with strict real-time requirements, such as stock prices and auction prices, it is unacceptable to display data that has expired slightly.
ASP. NET 2.0 supports the following cache types:
ASP. NET cache-page output Cache
Page output cache is the simplest caching mechanism, which stores the entire ASP. NET page content in the server memory. When a user requests this page, the system outputs relevant data from the memory until the cached data expires. In this process, the cached content is directly sent to the user without having to go through the page processing lifecycle again. In general, the page output cache is particularly useful for pages that contain content that does not need to be modified frequently, but require a large amount of processing before compilation. You must note that the page output cache stores all the page content in the memory and is used to complete client requests.
Partial page cache of ASP. NET Cache
Page part cache refers to some parts of the output cache page, rather than the whole page content. There are two mechanisms to implement partial page caching: one is to place the part of the page to be cached in the user control. and set the cache function for the user control, including the user control page can be set or not set cache ). This is commonly referred to as "control cache ". The essence of setting the control cache is to cache the user control. It mainly includes the following three methods: one is to use the @ OutputCache command to set the cache function for the user control in declaration mode, and the other is to use the PartialCachingAttribute class in the code hidden file to set the user control cache; third, use the ControlCachePolicy class to specify the user control cache settings programmatically. In addition, there is also a method called "cache replacement. This method is opposite to the control cache. It sets a part of the page as not cached. Therefore, although the entire page is cached, When you request this page again, the contents that are not set as cache will be reprocessed.
Application Data Cache Based on ASP. NET Cache
The application data 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 data cache is easy to lose, that is, the data is not stored in the memory throughout the application lifecycle. The advantage of application data cache is that ASP. manage the cache. It will remove 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 the items are removed.
Cache dependency of ASP. NET Cache
The custom cache dependency introduced by Net 2.0, especially the SqlCacheDependency Feature Based on the MS-SQL Server, allows us to avoid the problem of "data expiration", it can be based on the corresponding data changes in the database, notification cache and remove expired data
The cache function also has its own shortcomings. For example, the displayed content may not be the latest or most accurate. Therefore, you must set an appropriate Cache Policy. Another example is that caching increases system complexity and makes it difficult to test and debug. Therefore, we recommend that you develop and test applications without caching, and then enable caching options in the Performance Optimization phase.
Here is an introduction to ASP. NET cache, which helps you understand ASP. NET cache.
- Analysis on the personalization features of ASP. NET basic tutorials
- Analysis of ASP. net html Control Learning
- Procedure for ASP. NET to obtain MAC addresses and IP addresses
- Analysis on Static Page implementation using ASP. NET
- Analysis of ASP. NET connection string Traversal