ASP.NET Page Output Cache Provider Configuration Settings for Azure Managed Cache Service
Important
Microsoft recommends all new developments use Azure Redis Cache. For current documentation and guidance on choosing an Azure Cache offering, see Which Azure Cache offering is right for me?
This topic covers the configuration settings for the Azure Managed Cache Service output cache provider for ASP.NET. These settings are specified in the providers section of the outputCache element in the web.config file.
Output Cache Configuration Settings
Attribute | Description |
---|---|
name (required) |
The “friendly” name of the provider used by the outputCache element to reference the provider. |
type (required) |
The .NET Framework type string for the provider. See the note below on the required value. |
cacheName (required) |
The name of the Azure cache. This must be set to |
dataCacheClientName (optional) |
The name of the dataCacheClient section to use from the dataCacheClients configuration section. This attribute is only required if multiple dataCacheClient sections are specified in the web.config file. By default, the provider will use the dataCacheClient section named |
applicationName (optional) |
A string value used by the provider when creating cache keys for storing output cache data. The default is an empty string. When this attribute is not set the provider uses the value of HttpRuntime.AppDomainAppId as part of the cache keys it uses internally. Unlike the session state feature, you do not want to share output cache data across different ASP.NET applications (for example, /contoso and /AdventureWorks cannot share output cache data). Instead ensure that different physical instances of the same application all have access to the same output cache data. There are two different ways to accomplish this:
|
retryInterval (optional) |
A timespan for the length of time to wait between retry attempts if an error occurs when communicating with the cache. The string format to use for this value is |
retryCount (optional) |
An integer value that tells the provider the number of retry attempts in the event of a communications failure with the cache. Note that not all operations are able to be retried. The default value is three retry attempts. The provider sleeps for the configured retryInterval time between each retry attempt. |
Note
The type attribute should be set to “Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache”
.
Example
<!-- Non-cache sections omitted for space -->
<configuration>
<configSections>
<section name="dataCacheClients"
type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core"
allowLocation="true"
allowDefinition="Everywhere" />
<section name="cacheDiagnostics"
type="Microsoft.ApplicationServer.Caching.AzureCommon.DiagnosticsConfigurationSection, Microsoft.ApplicationServer.Caching.AzureCommon"
allowLocation="true"
allowDefinition="Everywhere" />
</configSections>
<system.web>
<!-- Azure Caching output caching provider -->
<!--Uncomment this section to use Azure Caching for output caching-->
<caching>
<outputCache defaultProvider="AFCacheOutputCacheProvider">
<providers>
<add name="AFCacheOutputCacheProvider"
type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache"
cacheName="default"
dataCacheClientName="default"
applicationName="AFCacheOutputCache" />
</providers>
</outputCache>
</caching>
</system.web>
<dataCacheClients>
<dataCacheClient name="default">
<!--To use the in-role flavor of Azure Caching, set identifier to be the cache cluster role name -->
<!--To use the Azure Caching Service, set identifier to be the endpoint of the cache cluster -->
<autoDiscover
isEnabled="true"
identifier="[Cache role name or Service Endpoint]" />
<!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />-->
<!--Use this section to specify security settings for connecting to your cache.
This section is not required if your cache is hosted on a role that is a part
of your cloud service. -->
<!--<securityProperties mode="Message" sslEnabled="false">
<messageSecurity authorizationInfo="[Authentication Key]" />
</securityProperties>-->
</dataCacheClient>
<cacheDiagnostics>
<crashDump dumpLevel="Off" dumpStorageQuotaInMB="100" />
</cacheDiagnostics>
</dataCacheClients>
</configuration>
Note
The cacheDiagnostics
section is only added by the Cache NuGet package to ASP.NET Web Role clients. For more information, see About ClientDiagnosticLevel for Azure Managed Cache Service.