
Page Output Cache Configuration
You can configure page output caching in these places:
Configuration files You can configure page output cache settings in any configuration file in the application configuration hierarchy, including the Machine.config file (to make settings for all Web applications on the computer) and your application-specific Web.config file (to make settings for a single application).
Individual pages You can set caching options in individual pages either declaratively or programmatically. You can also apply cache profiles created in the configuration file to individual pages.
User controls You can set caching in individual user controls either declaratively or programmatically. This is an easy way to cache content within a page that is otherwise not cached.
Web.config Cache Configuration Settings
There are two top-level configuration sections for the page output cache in the Web.config file: the OutputCacheSection and the OutputCacheSettingsSection.
The OutputCacheSection section is used to configure application-scope settings, such as whether page output caching is enabled or disabled. For example, you can disable page output caching for the entire application by adding enableOutputCache="false" to the OutputCacheSection in your Web.config file. Settings in the configuration file take precedence over cache settings in individual pages, so the example setting means that output cache will not be used.
The OutputCacheSettingsSection is used to configure profiles and dependencies that can be used by individual pages. For example, the following code creates an OutputCacheProfile named CacheProfile1 that will cache the implementing page for 60 seconds:
|
<outputCacheSettings>
<outputCacheProfiles>
<add name="CacheProfile1" duration="60" />
</outputCacheProfiles>
</outputCacheSettings>
|
Machine.config Cache Configuration Settings
The configuration sections for the Machine.config file are the same as for the Web.config file, except that you can lock configuration settings in the Machine.config file so that they cannot be overridden by individual applications at any level. This might be necessary in a shared hosting scenario in which the hoster does not want individual applications modifying the cache configuration. For more information see How to: Lock ASP.NET Configuration Settings.
Page Cache Configuration Settings
You can configure caching in individual pages by applying cache profiles that have been defined in a configuration file. Alternatively, you can configure individual cache properties in the @ OutputCache directive or by setting attributes in the page's class definition. For more information see @ OutputCache and Setting the Cacheability of a Page.
User Control Cache Configuration Settings