What's New in ASP.NET Caching
ASP.NET version 2.0 retains all of the caching functionality of ASP.NET version 1.1, but adds new features and enhances existing features. New features include cache profiles, custom cache dependencies, a SQL cache dependency, and creating dynamic content in cached pages (post-cache substitution). Feature enhancements include a more powerful partial-page (control) caching model, enhanced cache configuration, and improvements to the output cache directive.
New Cache Features
Cache profiles allow you to create cache settings in an application's Web.config file and then reference those settings on individual pages. This allows you to apply cache settings to many pages at once. For example, you can define a cache profile named DailyUpdate that sets a page's cache duration to one day. You can then configure individual pages to use the DailyUpdate cache profile, and the cache duration of those pages will be one day. If you change the DailyUpdate cache profile to not use caching, the pages will stop being cached. For more information see.
Custom Cache Dependencies
In ASP.NET 2.0 you can create your own custom cache dependency based on application-specific conditions. To create a custom cache dependency, you create a class that inherits fromand in your custom class implement your own dependency methods. For example, you can create a dependency that polls a Web service for data; when the data changes, you can invalidate your cache data. To learn about adding items to the cache by specifying a dependency, see .
ASP.NET 2.0 introduces theclass, which allows you to configure an item in the cache to have a dependency on a table or row in a Microsoft SQL Server database. When a change occurs in the table or in a specific row, the cached item that has a dependency is invalidated and therefore removed from the cache. ASP.NET 2.0 allows you to set a dependency on a table in SQL Server 7.0, SQL Server 2000, and SQL Server 2005. When using SQL Server 2005, you can also set a dependency on a specific record. For more information, see .
ASP.NET 2.0 now supports post-cache substitution, which allows you to configure a section in a page as non-cacheable. Therefore, although the page is cached, parts of it will be re-processed when the page is requested again. For example, you can create a cached page with mostly static content but that displays the user's name in acontrol. Without post-cache substitution, the user name would remain the same for all requests. With post-cache substitution, you can mark the page as cacheable and put the Label control inside another control marked as not cacheable. The user name will then refresh each time the page is requested. For more information see .
In ASP.NET 1.1, you configure user control caching declaratively by setting parameters in thedirective. In ASP.NET 2.0, you can configure user control cache settings at run time with the object. The CachePolicy object allows you to work with user control caching the same way that you can work programmatically with page output caching. For more information, see .
Cache Configuration Enhancements
In addition to cache profiles, ASP.NET 2.0 introduces new cache configuration settings that you can specify in an application's Web.config file. These settings allow more control over the cache, such as how much memory is used and cache scavenging behavior. For more information see.
Output Cache Directive Improvements
ASP.NET 2.0 includes newdirective options and includes enhancements to existing ones. The new features and enhancements enable declarative control over output cache features that were previously available only programmatically using the class. For example, you can now declaratively set the attribute and the attribute in the page directive. For more information, see .