Partager via


cache Element for caching (ASP.NET Settings Schema)

Defines application-wide cache settings for an ASP.NET Web application.

<cache disableMemoryCollection="true|false" 
       disableExpiration="true|false" 
       privateBytesLimit="number" 
       percentagePhysicalMemoryUsedLimit="number" 
       privateBytesPollTime="HH:MM:SS" />

Attributes and Elements

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

Attributes

Attribute Description

disableMemoryCollection

Optional Boolean attribute.

Gets or sets a value indicating whether the cache memory collection that occurs when the machine is under memory pressure is disabled.

disableExpiration

Optional Boolean attribute.

Gets or sets a value indicating whether cache expiration is disabled. When disabled, cached items do not expire and background scavenging of expired cache items does not occur.

privateBytesLimit

Optional Int64 attribute.

Gets or sets a value indicating the maximum size of an application's private bytes before the cache starts flushing expired items and attempting to reclaim memory. This limit includes both memory used by the cache as well as normal memory overhead from the running application. A setting of zero indicates that ASP.NET will use its own heuristics for determining when to start reclaiming memory.

percentagePhysicalMemoryUsedLimit

Optional Int32 attribute.

Gets or sets a value indicating the maximum percentage of a machine's physical memory that can be consumed by an application before the cache starts flushing expired items and attempting to reclaim memory This memory usage includes both memory used by the cache as well as the normal memory usage of the running application. A setting of zero indicates that ASP.NET will use its own heuristics for determining when to start reclaiming memory.

privateBytesPollTime

Optional TimeSpan attribute.

Gets or sets a value indicating the time interval between polling for the application's private bytes memory usage.

Child Elements

None.

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.

caching

Configures the cache settings for a Web application.

Remarks

Default Configuration

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

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

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

Example

The following example sets the global cache settings for an ASP.NET application.

<cache disableMemoryCollection = "false" 
  disableExpiration = "false" 
  privateBytesLimit = "20971520" 
  percentagePhysicalMemoryUsedLimit = 60" 
  privateBytesPollTime = "00:01:00"/>

Element Information

Configuration Section Handler

System.Web.Configuration.CacheSection

Configuration Member

Cache

Configurable Locations

Machine.config

Root level Web.config

Application level Web.config

Requirements

IIS version 5.0, 5.1 and 6.0

.NET Framework version 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)
System.Configuration
System.Web.Configuration

Concepts

Cache Configuration in ASP.NET
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