<namedCaches > 元素 (缓存设置)<namedCaches> Element (Cache Settings)

指定的配置设置的命名集合MemoryCache实例。Specifies a collection of configuration settings for the named MemoryCache instances. NamedCaches属性引用的配置设置集合中一个或多个namedCaches配置文件中的元素。The NamedCaches property references the collection of configuration settings from one or more namedCaches elements of the configuration file.

<configuration><configuration>
< system.runtime.caching>< system.runtime.caching>
<memoryCache><memoryCache>
<namedCaches><namedCaches>

语法Syntax

<namedCaches>  
  <add name="default"/>   
</namedCaches>  

类型Type

None

特性和元素Attributes and Elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

特性Attribute 描述Description
cacheMemoryLimitMegabytes 指定的最大大小,以兆字节为单位,一个整数值的实例MemoryCache可以增长到。An integer value that specifies the maximum allowable size, in megabytes, that an instance of a MemoryCache can grow to. 默认值为 0,这意味着的自动调整大小试探法MemoryCache类默认情况下使用。The default value is 0, which means that the autosizing heuristics of the MemoryCache class are used by default.
name 缓存的名称。The name of the cache.
physicalMemoryLimitPercentage 一个整数值介于 0 和 100 之间,指定可以使用由缓存以物理方式安装的计算机内存的最大百分比。An integer value between 0 and 100 that specifies the maximum percentage of physically installed computer memory that can be consumed by the cache. 默认值为 0,这意味着的自动调整大小试探法MemoryCache类默认情况下使用。The default value is 0, which means that the autosizing heuristics of the MemoryCache class 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. "Hh: mm:"格式输入此值。This value is entered in "HH:MM:SS" format.

子元素Child Elements

元素Element 描述Description
<add><add> 向内存缓存的 namedCaches 集合添加一个命名的缓存。Adds a named cache to the namedCaches collection for a memory cache.
<clear><clear> 清除内存缓存的 namedCaches 集合。Clears the namedCaches collection for a memory cache.
<remove><remove> 从内存缓存的 namedCaches 集合中删除一个命名的缓存条目。Removes a named cache entry from the namedCaches collection for a memory cache.

父元素Parent Elements

元素Element 描述Description
<memoryCache><memoryCache> 定义一个用于配置基于 MemoryCache 类的缓存的元素。Defines an element that is used to configure a cache that is based on the MemoryCache class.

备注Remarks

可以包含 Web.config 文件的内存缓存配置部分addremove,并clear属性namedCaches集合。The memory cache configuration section of the Web.config file can contain add, remove, and clear attributes for the namedCaches collection. 每个namedCaches由唯一标识条目name属性。Each namedCaches entry is uniquely identified by the name attribute.

可以通过引用应用程序配置文件中的信息来检索实例的内存缓存项。You can retrieve instances of memory cache entries by referencing the information in the application configuration files. 默认情况下,默认的缓存实例配置文件中具有条目。By default, only the default cache instance has an entry in the configuration file. 默认缓存实例是从返回的实例Default属性。The default cache instance is the instance that is returned from the Default property.

如果设置为"default"的 name 属性,该元素使用的默认内存缓存实例。If you set the name attribute to "default", the element uses the default memory cache instance.

示例Example

下面的示例演示如何通过设置缓存的名称设置为默认缓存项名称name属性设置为"default"。The following example shows how to set the name of the cache to the default cache entry name by setting the name attribute to "default".

cacheMemoryLimitMegabytes 属性和 physicalMemoryPercentage 属性设置为零。The cacheMemoryLimitMegabytes attribute and the physicalMemoryPercentage attribute are set to zero. 将这些属性设置为零意味着的自动调整大小试探法MemoryCache类使用。Setting these attributes to zero means that the autosizing heuristics of the MemoryCache class are used. 缓存实现将当前内存负载与每隔两分钟的绝对内存和基于百分比的内存限制进行比较。The cache implementation compares 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>  

请参阅See also