<system.web > 元素(快取設定)<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.

<configuration> <configuration>
   <的 >  <system.runtime.caching>

語法Syntax

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

屬性和項目Attributes and Elements

下列各節描述屬性、子項目和父項目。The following sections describe attributes, child elements, and parent elements.

屬性Attributes

None

子項目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.

備註Remarks

這個命名空間中的類別提供如同在 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 中的新功能。The output caching functionality and types in the System.Runtime.Caching namespace are new in .NET Framework 4.

範例Example

下列範例示範如何設定以 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 屬性設定為 "Default"。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.

<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