Udostępnij za pośrednictwem


outputCache Element for caching (ASP.NET Settings Schema)

Specifies application-wide output cache settings.

configuration Element (General Settings Schema)
  system.web Element (ASP.NET Settings Schema)
    caching Element (ASP.NET Settings Schema)
      outputCache Element for caching (ASP.NET Settings Schema)

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

Attributes and Elements

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

Attributes

Attribute

Description

enableOutputCache

Optional Boolean attribute.

Enables/disables the page output cache.

If disabled, no pages are cached regardless of the programmatic or declarative settings.

Default value is true.

enableFragmentCache

Optional Boolean attribute.

Enables/disables the application fragment cache.

If disabled, no pages are cached regardless of the @ OutputCache directive or caching profile used. Includes a cache-control header indicating that upstream proxy servers as well as browser clients should not attempt to cache page output.

Default value is false.

sendCacheControlHeader

Optional Boolean attribute.

Gets or sets a value indicating whether the cache-control:private header is sent by the output cache module by default.

Default value is false.

omitVaryStar

Optional Boolean attribute.

Enables/disables sending an HTTP "Vary: *" header in the response. With the default setting of false, a "Vary: *" header is sent for output cached pages.

Default value is false.

defaultProvider

Optional string attribute.

Gets or sets the default output-cache provider.

Default value is "AspNetInternalProvider". This is the in-memory cache provided by ASP.NET.

Child Elements

Element

Description

providers

An optional child element that can be used to configure custom output-cache providers.

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 outputCache 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.

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

The following example shows how to disable the output cache for an ASP.NET application:

<outputCache enableOutputCache="false" />

Extensible Output Caching

ASP.NET enables you to extend output caching and to configure one or more custom output-cache providers. Output-cache providers can use any storage mechanism to persist HTML content. These storage options can include local or remote disks, cloud storage, and distributed cache engines.

Output-cache provider extensibility lets you design more aggressive and more intelligent output-caching strategies for Web sites. For example, you can create an output-cache provider that caches the "Top 10" pages of a site in memory, while caching pages that get lower traffic on disk. Alternatively, you can cache every vary-by combination for a rendered page, but use a distributed cache so that the memory consumption is offloaded from front-end Web servers.

You create a custom output-cache provider as a class that derives from the OutputCacheProvider type. You can then configure the provider in the Web.config file by using the providers subsection of the outputCache element.

By default, in ASP.NET, all HTTP responses, rendered pages, and controls use the in-memory output cache that is in the previous example (where the defaultProvider attribute is set to AspNetInternalProvider). You can change the default output-cache provider used for a Web application by specifying a different provider name for defaultProvider.

In addition, you can select different output-cache providers for individual control and for individual requests. The easiest way to specify a different output-cache provider for different Web user controls is to do so declaratively by using the providerName attribute in a page or control directive, as shown in the following example:

<%@ OutputCache Duration="60" VaryByParam="None" 
    providerName="DiskCache" %>

You can specify a different output cache provider for an HTTP request, and override the GetOutputCacheProviderName method in the Global.asax file to programmatically specify which provider to use for a specific request.

See Also

Tasks

Walkthrough: Using Output Caching to Enhance Web Site Performance

How to: Lock ASP.NET Configuration Settings

Reference

OutputCache

Concepts

ASP.NET Caching Overview

Securing ASP.NET Configuration

ASP.NET Configuration Scenarios

Other Resources

ASP.NET Web Site Administration