更新:2007 年 11 月
configuration 元素(常规设置架构) system.web 元素(ASP.NET 设置架构) caching 元素(ASP.NET 设置架构)
<caching>
<cache>...</cache>
<outputCache>...</outputCache>
<outputCacheSettings>...</outputCacheSettings>
<sqlCacheDependency>...</sqlCacheDependency>
</caching>
以下几节描述了属性、子元素和父元素。
属性
无。
子元素
元素 | 说明 |
|---|
Cache | 可选的元素。 定义全局应用程序缓存设置。 |
outputCache | 可选的元素。 指定应用程序范围的输出缓存设置。 |
outputCacheSettings | 可选的元素。 指定可以应用于应用程序中页的输出缓存设置。 |
sqlCacheDependency | 可选的元素。 为 ASP.NET 应用程序配置 SQL 缓存依赖项。 |
父元素
元素 | 说明 |
|---|
configuration | 公共语言运行库和 .NET Framework 应用程序所使用的每个配置文件中均需要的根元素。 |
System.web | 指定配置文件中 ASP.NET 配置设置的根元素。包含各种配置元素,这些配置元素配置 ASP.NET Web 应用程序并控制这些应用程序的行为方式。 |
默认配置
下面的默认 caching 元素不是在 Machine.config 文件或根 Web.config 文件中显式配置的,而是由 .NET Framework 版本 2.0 中的应用程序返回的默认配置。
<caching>
<cache disableMemoryCollection = "false"
disableExpiration = "false"
privateBytesLimit = "0"
percentagePhysicalMemoryUsedLimit = "90"
privateBytesPollTime = "00:02:00"/>
<outputCache enableOutputCache = "true"
enableFragmentCache = "true"
sendCacheControlHeader = "true"
omitVaryStar = "false" >
</outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<clear />
<add name = ""
enabled = "true"
duration = "-1"
location = ""
sqlDependency = ""
varyByCustom = ""
varyByControl = ""
varyByHeader = ""
varyByParam = ""
noStore = "false"/>
</outputCacheProfiles>
</outputCacheSettings>
<sqlCacheDependency enabled = "true"
pollTime = "60000">
<databases>
<clear />
<add name = ""
connectionStringName = ""
pollTime = "60000"/>
</databases>
</sqlCacheDependency>
</caching>
下面的示例将某一页在服务器上仅缓存一分钟,并且根据浏览器类型和主版本存储该页的不同版本。
<outputCacheSettings>
<outputCacheProfiles>
<add name="ServerOnly"
duration="60"
varyByCustom="browser"
location="Server" />
</outputCacheProfiles>
</outputCacheSettings>
设计需要以这种方式缓存的页时,您需要向该页添加以下指令:
<%@ OutputCache CacheProfile="ServerOnly" %>
有关更多信息,请参见 @ OutputCache。
任务
概念
参考
其他资源