Export (0) Print
Expand All

<memoryCache> Element (Cache Settings)

Defines an element that is used to configure a cache that is based on the MemoryCache class. The MemoryCacheElement class defines a memoryCache element that you can use to configure the cache. Multiple instances of the MemoryCache class can be used in a single application. Each memoryCache element in the configuration file can contain settings for a named MemoryCache instance.

<configuration> Element
  <system.runtime.caching> Element (Cache Settings)
    <memoryCache> Element (Cache Settings)
<memoryCache 
    <namedCaches>
        <!-- child elements -->
    </namedCaches> 
< memoryCache />

MemoryCache class.

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

Attributes

Attribute

Description

CacheMemoryLimitMegabytes

The maximum memory size, in megabytes, that an instance of a MemoryCache object can grow to. The default value is 0, which means that the MemoryCache class's autosize heuristics are used by default.

Name

The name of the cache configuration.

PhysicalMemoryLimitPercentage

The percentage of physical memory that can be used by the cache. The default value is 0, which means that the MemoryCache class's autosize heuristics are used by default.

PollingInterval

A value that indicates the time interval after which the cache implementation compares the current memory load against the absolute and percentage-based memory limits that are set for the cache instance. The value is entered in "HH:MM:SS" format.

Child Elements

Element

Description

<namedCaches>

Contains a collection of configuration settings for the namedCache instance.

Parent Elements

Element

Description

<system.runtime.caching>

Contains types that let you implement output caching in applications that are built into the .NET Framework.

The MemoryCache class is a concrete implementation of the abstract ObjectCache class. Instances of the MemoryCache class can be supplied with configuration information from application configuration files. The memoryCache configuration section contains a namedCaches configuration collection.

When a memory-based cache object is initialized, it first tries to find a namedCaches entry that matches the name in the parameter that is passed to the memory cache constructor. If a namedCaches entry is found, the polling and memory-management information are retrieved from the configuration file.

The initialization process then determines whether any configuration entries were overridden, by using the optional collection of name/value pairs of configuration information in the constructor. If you pass any one of the following values in the name/value pair collection, these values override information obtained from the configuration file:

The following example shows how to set the name of the MemoryCache object to the default cache object name by setting the name attribute to "default".

The cacheMemoryLimitMegabytes attribute and the physicalMemoryPercentage attribute are set to zero. Setting these attributes to zero means that the MemoryCache autosizing heuristics are used by default. The cache implementation should compare the current memory load against the absolute and percentage-based memory limits every two minutes.

<configuration>
  <system.runtime.caching>
    <memoryCache>
      <namedCaches>
          <add name="default" 
               cacheMemoryLimitMegabytes="0" 
               physicalMemoryPercentage="0"
               pollingInterval="00:02:00" />
      </namedCaches>
    </memoryCache>
  </system.runtime.caching>
</configuration>

Community Additions

ADD
Show:
© 2014 Microsoft