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

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

<configuration> <configuration>
   <> 缓存  <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实例可以增长到的最大允许大小(以 mb 为单位)。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: SS" 格式输入。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
<configuration><configuration> 指定公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。Specifies the root element in every configuration file that is used by the common language runtime and .NET Framework applications.
<memoryCache><memoryCache> 定义一个用于配置基于 MemoryCache 类的缓存的元素。Defines an element that is used to configure a cache that is based on the MemoryCache class.
<system.runtime.caching><system.runtime.caching> 包含使你可以在 .NET Framework 中内置的应用程序中实现输出缓存的类型。Contains types that let you implement output caching in applications that are built into the .NET Framework.

备注Remarks

Web.config 文件的内存缓存配置节add可以包含namedCaches集合的、 removeclear特性。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.

如果将 name 属性设置为 "default",则元素将使用默认内存缓存实例。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