ASP. NET 2.0 retains all the caching functions of ASP. NET 1.1. It also adds new functions and enhances existing functions. The new features include cache configuration files, custom cache dependencies, SQL cache dependencies, and creating dynamic content on the cache page (with cache replacement ). Enhanced functions include a more powerful partial-page (Control) cache model, enhanced cache configuration, and improved output of cache commands.
Cache configuration file for the new cache Function
The cache configuration file allows you to create cache settings in the Web. config file of the application, and then reference these settings on a single page. This allows you to apply cache settings to multiple pages at the same time. For example, you can define a cache configuration file named DailyUpdate, which sets the page cache duration to one day. You can then configure each page to use DailyUpdate to cache the configuration file, and the cache duration of these pages is one day. If you change the DailyUpdate cache configuration file to no cache, the pages will be stopped. For more information, see cache configuration in ASP. NET.
Custom cache Dependencies
In ASP. NET 2.0, you can create your own custom cache dependencies based on specific application conditions. To create custom cache dependencies, create a class inherited from CacheDependency and implement your own dependency methods in the Custom class. For example, you can create a dependency to poll data in the Web Service. When data changes, you can invalidate the cache data. To learn how to add items to the cache by specifying dependencies, see add items to the cache.
SqlCacheDependency
ASP. NET 2.0 introduces the sqlcachedependency class, which enables you to configure an item in the cache to have dependencies on tables or rows in the Microsoft SQL Server database. When changes occur in a table or a specific row, the cache items with dependencies become invalid and removed from the cache. ASP. NET 2.0 enables you to set table dependencies in SQL Server 7.0, SQL Server 2000, and SQL Server 2005. When you use SQL Server 2005, you can also set the dependencies for specific records. For more information, see cache in ASP. NET using the sqlcachedependency class.
Cache replacement
ASP. NET 2.0 now supports cache replacement, allowing you to configure a part of the page as non-cache. Therefore, even if the page is cached, part of the page will be reprocessed when you request the page again. For example, you can use most static content (but not the content that shows the user name in the label Control) to create a cache page. If you do not use the cache, the user name remains unchanged in all requests. If the cache is used, you can mark the page as cacheable, and thenLabelControls are placed in another control marked as non-cacheable. The user name is refreshed every time this page is requested. For more information, see some sections on the cache ASP. NET page.
Cache enhancement control Cache
In ASP. NET 1.1, configure the user control cache with parameters declared in the @ control command. In ASP. NET 2.0, you can use the cachepolicy object at runtime to configure the user control cache settings.CachePolicyObject allows you to process the user control cache in the same way as the page output cache is processed programmatically. For more information, see some sections on the cache ASP. NET page.
Cache configuration Enhancement
In addition to the cache configuration file, new cache configuration settings are introduced in ASP. NET 2.0. You can specify these settings in the web. config file of the application. These settings increase your cache control, such as memory usage and cache cleanup. For more information, see cache configuration in ASP. NET.
Improved output cache commands
ASP. NET 2.0 includes new @ OutputCache Command Options and enhancements to existing options. New Features and enhancements enable you to declare and control the output cache function. Previously, you could only use the HttpCachePolicy class to implement this type of control programmatically. For example, you can set the Duration Attribute and NoStore attribute in the @ OutputCache command in declarative mode. For more information, see set page cache.