<添加 namedCaches 的<> 元素 ><add> Element for <namedCaches>

向内存缓存的namedCaches集合中添加项。namedCacheAdds a namedCache entry to the namedCaches collection for a memory cache.

<configuration> <configuration>
   <> 缓存  <system.runtime.caching>
     <memoryCache >     <memoryCache>
       <namedCaches >       <namedCaches>
         <添加 >        <add>

语法Syntax

<namedCaches>  
    <add name="Default" />  
      <!-- child elements -->  
 </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 allowed size (in megabytes) that an instance of a MemoryCache can grow to. 默认值为0,这意味着MemoryCache默认情况下使用类的自动调整试探法。The default value is 0, which means that the MemoryCache class's autosizing heuristics 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 MemoryCache class's autosizing 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. 此值以 "HH: MM: SS" 格式输入。This value is entered in "HH:MM:SS" format.

子元素Child Elements

None

父元素Parent Elements

元素Element 描述Description
<namedCaches><namedCaches> 包含命名MemoryCache实例的配置设置的集合。Contains a collection of configuration settings for the named MemoryCache instances.

备注Remarks

元素向内存缓存的namedCaches集合中添加项。 addThe add element adds an entry to the namedCaches collection for a memory cache. 您可以在使用 add 元素之前使用 clear 元素,以确保集合中没有其他命名缓存。You can use the clear element before you use the add element to be certain that there are no other named caches in the collection. 此元素可在 machine.config 文件和 web.config 文件中使用。This element can be used in the machine.config file and in the Web.config file.

示例Example

下面的示例演示如何为内存缓存的namedCache namedCaches集合定义默认项的设置。The following example shows how to define settings for the default namedCache entry to the namedCaches collection for a memory cache.

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

请参阅See also