caching Element (ASP.NET Settings Schema)

Configures the cache settings for a Web application.

<caching>
   <cache>...</cache>
   <outputCache>...</outputCache>
      <outputCacheSettings>...</outputCacheSettings>
   <sqlCacheDependency>...</sqlCacheDependency>
</caching>

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

None.

Child Elements

Element Description

cache

Optional element.

Defines global application cache settings.

outputCache

Optional element.

Specifies application-wide output-cache settings.

outputCacheSettings

Optional element.

Specifies output-cache settings that can be applied to pages in the application.

sqlCacheDependency

Optional element.

Configures the SQL cache dependencies for an ASP.NET application.

Parent Elements

Element Description

configuration

The required root element in every configuration file used by the common language runtime and .NET Framework applications.

system.web

Specifies the root element for the ASP.NET configuration settings in a configuration file. Contains configuration elements that configure ASP.NET Web applications and control how the applications behave.

Remarks

Default Configuration

The following default caching element is not explicitly configured in the Machine.config file or in the root Web.config file, but is the default configuration returned by application in the .NET Framework version 2.0.

<caching>
  <cache disableMemoryCollection = "false" 
    disableExpiration = "false" 
    privateBytesLimit = "0" 
    percentagePhysicalMemoryUsedLimit = "90" 
    privateBytesPollTime = "00:02:00"/>

  <cache disableMemoryCollection="false" 
    disableExpiration="false" privateBytesLimit="0" 
    percentagePhysicalMemoryUsedLimit="90" 
    privateBytesPollTime="00:02:00" />

  <outputCache enableOutputCache = "true" 
    enableFragmentCache = "true" 
    sendCacheControlHeader = "true" 
    omitVaryStar = "false" >
  </outputCache>

  <outputCache enableOutputCache="true" 
    enableFragmentCache="true" 
    sendCacheControlHeader="true" 
    omitVaryStar="false">
  </outputCache>

  <outputCacheSettings>
    <outputCacheProfiles>
      <add name = "" 
        enabled = "true" 
        duration = "-1" 
        location = "" 
        sqlDependency = "" 
        varyByCustom = "" 
        varyByControl = "" 
        varyByHeader = "" 
        varyByParam = "" 
        noStore = "false"/>
    </outputCacheProfiles>
  </outputCacheSettings>

  <outputCacheSettings>
    <outputCacheProfiles>
      <clear />
    </outputCacheProfiles>
  </outputCacheSettings>

  <sqlCacheDependency enabled = "true" 
    pollTime = "60000">
    <databases>
      <add name = "" 
        connectionStringName = "" 
        pollTime = "60000"/>
    </databases>
  </sqlCacheDependency>

  <sqlCacheDependency enabled="true" 
    pollTime="60000">
    <databases>
      <clear />
    </databases>
  </sqlCacheDependency>
</caching>

Example

The following example caches a page on the server only for one minute and stores different versions of the page based on browser type and major version.

<outputCacheSettings>
  <outputCacheProfiles>
    <add name="ServerOnly" 
      duration="60" 
      varyByCustom="browser" 
      location="Server" />
  </outputCacheProfiles>
</outputCacheSettings>

When designing a page that needs to be cached in this way, you will need to add the following directive to the page:

<%@ OutputCache CacheProfile="ServerOnly" %>

For more information see @ OutputCache.

Element Information

Configuration Section Handler

System.Web.Configuration.CacheSection

System.Web.Configuration.OutputCacheSection

System.Web.Configuration.OutputCacheSettingsSection

System.Web.Configuration.SqlCacheDependencySection

Configuration Member

System.Web.Configuration.SystemWebCachingSectionGroup

Configurable Locations

Machine.config

Root level Web.config

Application level Web.config

Requirements

IIS 5.0, 5.1 and 6.0

.NET Framework 2.0

Visual Studio 2005

See Also

Tasks

How to: Configure Specific Directories Using Location Settings
How to: Lock ASP.NET Configuration Settings

Reference

system.web Element (ASP.NET Settings Schema)
configuration Element (General Settings Schema)
cache Element for caching (ASP.NET Settings Schema)
outputCache Element for caching (ASP.NET Settings Schema)
outputCacheSettings Element for caching (ASP.NET Settings Schema)
sqlCacheDependency Element for caching (ASP.NET Settings Schema)
System.Configuration
System.Web.Configuration

Concepts

ASP.NET Caching Overview
ASP.NET Configuration File Hierarchy and Inheritance
Securing ASP.NET Configuration
ASP.NET Configuration Scenarios

Other Resources

General Configuration Settings (ASP.NET)
ASP.NET Configuration Settings
Configuring ASP.NET Applications
ASP.NET Configuration Files
ASP.NET Configuration API