<requestCaching> 元素(网络设置)<requestCaching> Element (Network Settings)

控制网络请求的缓存机制。Controls the caching mechanism for network requests.

<configuration> <configuration>
**的  **   <system.net>
     <requestCaching >    <requestCaching>

语法Syntax

<requestCaching  
  isPrivateCache ="true|false"  
  disableAllCaching="true|false"  
  defaultPolicyLevel="BypassCache|Default|CacheOnly|CacheIfAvailable|Revalidate|Reload|NoCacheNoStore|Revalidate"  
  unspecifiedMaximumAge= "d.hh:mm:ss">  
    <defaultHttpCachePolicy>...</defaultHttpCachePolicy>  
    <defaultFtpCachePolicy>...</defaultFtpCachePolicy>  
</requestCaching>

属性和元素Attributes and Elements

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

特性Attributes

属性Attribute 描述Description
isPrivateCache 指定缓存是否在不同用户的信息之间提供隔离。Specifies whether the cache provides isolation between the information of different users. 默认值为 trueThe default value is true. 应为中间层应用程序 false 此值。This value should be false for middle tier applications.
disableAllCaching 指定为所有 Web 响应禁用缓存,且不能以编程方式重写。Specifies that caching is disabled for all Web responses, and cannot be overridden programmatically.
defaultPolicyLevel RequestCacheLevel 枚举中的值之一。One of the values in the RequestCacheLevel enumeration. 默认值为 BypassCacheThe default value is BypassCache.
unspecifiedMaximumAge 指定将内容标记为过期的默认时间。Specifies the default time after which content is marked as expired.

policyLevel 特性policyLevel Attribute

{2>值<2}Value 描述Description
Default 如果资源是最新的,则返回缓存的资源,内容长度准确,并且存在过期、修改和内容长度属性。Returns the cached resource if the resource is fresh, the content length is accurate, and the expiration, modification, and content length attributes are present.
BypassCache 从服务器返回资源。Returns the resource from the server.
CacheOnly 如果内容长度存在并且与条目大小匹配,则返回缓存的资源。Returns the cached resource if the content length is present and matches the entry size.
CacheIfAvailable 如果提供了内容长度并与条目大小匹配,则返回缓存的资源;否则,将从服务器下载资源,并将其返回给调用方。Returns the cached resource if the content length is provided and matches the entry size; otherwise, the resource is downloaded from the server and is returned to the caller.
Revalidate 如果缓存资源的时间戳与服务器上资源的时间戳相同,则返回缓存的资源;否则,将从服务器下载资源,并将其存储在缓存中,并将其返回给调用方。Returns the cached resource if the timestamp of the cached resource is the same as the timestamp of the resource on the server; otherwise, the resource is downloaded from the server, stored in the cache, and is returned to the caller.
Reload 从服务器下载资源,将其存储在缓存中,并将资源返回给调用方。Downloads the resource from the server, stores it in the cache, and returns the resource to the caller.
NoCacheNoStore 如果缓存的资源存在,则将其删除。If a cached resource exists, it is deleted. 从服务器下载资源,并将其返回给调用方。The resource is downloaded from the server and is returned to the caller.
Revalidate 如果时间戳与服务器上资源的时间戳相同,则使用资源的缓存副本满足请求;否则,会从服务器下载资源,并将其提供给调用方,并存储在缓存中。Satisfies a request by using the cached copy of the resource if the timestamp is the same as the timestamp of the resource on the server; otherwise, the resource is downloaded from the server, presented to the caller, and is stored in the cache,

子元素Child Elements

元素Element 描述Description
defaultHttpCachePolicydefaultHttpCachePolicy 可选元素。Optional element.

描述 HTTP 缓存是否处于活动状态,并描述默认缓存策略。Describes whether HTTP caching is active and describes the default caching policy.
<defaultFtpCachePolicy > 元素(网络设置)<defaultFtpCachePolicy> Element (Network Settings) 可选元素。Optional element.

介绍 FTP 缓存是否处于活动状态,并描述默认缓存策略。Describes whether FTP caching is active and describes the default caching policy.

父元素Parent Elements

元素Element 描述Description
system.netsystem.net 包含指定 .NET Framework 如何连接到网络的设置。Contains settings that specify how the .NET Framework connects to the network.

示例Example

下面的示例演示如何禁用所有缓存。The following example shows how to disable all caching.

<configuration>  
  <system.net>  
    <requestCaching  
      disableAllCaching="true"  
    />  
  </system.net>  
</configuration>  

另请参阅See also