<system.runtime.caching > 元素 (缓存设置)<system.runtime.caching> Element (Cache Settings)

通过配置文件中的 ObjectCache 条目为默认内存中的 memoryCache 实现提供配置。Provides configuration for the default in-memory ObjectCache implementation through the memoryCache entry in the configuration file.



<system.runtime.caching >  
   <!-- child elements -->  
</system.runtime.caching >  

特性和元素Attributes and Elements

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



子元素Child Elements

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

父元素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.


此命名空间中的类提供一种使用诸如 ASP.NET 中缓存功能的方法,但不会在 System.Web 程序集上产生依赖。The classes in this namespace provide a way to use caching facilities like those in ASP.NET, but without a dependency on the System.Web assembly. 有关详细信息,请参阅 Caching in .NET Framework ApplicationsFor more information, see Caching in .NET Framework Applications.


System.Runtime.Caching 命名空间中的输出缓存功能和类型对于 .NET Framework 4.NET Framework 4而言是全新的。The output caching functionality and types in the System.Runtime.Caching namespace are new in .NET Framework 4.NET Framework 4.


下面的示例演示如何配置基于 MemoryCache 类的缓存。The following example shows how to configure a cache that is based on the MemoryCache class. 该示例演示如何为内存缓存配置 namedCaches 条目实例。The example shows how to configure an instance of the namedCaches entry for memory cache. 通过将 name 属性设置为“默认”,可以将缓存名称设置为默认缓存项名称。The name of the cache is set 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 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.

          <add name="default"   
               pollingInterval="00:02:00" />  

请参阅See also