<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.
<memoryCache> <namedCaches> <!-- child elements --> </namedCaches> </memoryCache>
Attributes and Elements
The following sections describe attributes, child elements, and parent elements.
||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.|
||The name of the cache configuration.|
||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.|
||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.|
|<namedCaches>||Contains a collection of configuration settings for the
|<configuration>||Specifies the root element in every configuration file that is used by the common language runtime and .NET Framework applications.|
|<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".
cacheMemoryLimitMegabytes attribute and the
physicalMemoryLimitPercentage 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" physicalMemoryLimitPercentage="0" pollingInterval="00:02:00" /> </namedCaches> </memoryCache> </system.runtime.caching> </configuration>
Submit and view feedback for