共用方式為


<defaultHttpCachePolicy> Element (Network Settings)

Describes whether HTTP caching is active and describes the default caching policy.

< defaultHttpCachePolicy
  policyLevel="BypassCache|Default"
  minimumFresh="d.hh:mm:ss"|"minValue"
  maximumAge  ="d.hh:mm:ss"|"maxValue"
  maximumStale="d.hh:mm:ss"|"maxValue"
/>

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Description

maximumAge

Specifies the maximum time interval before a cached object is marked as expired.

maximumStale

Specifies the maximum time past the computed freshness time before a cached object is marked as expired.

minimumFresh

Specifies the minimum time for a cached object to be considered fresh.

policyLevel

Specifies whether the caching policy is automatic, or whether the cache is bypassed. The default value is BypassCache.

Child Elements

None

Parent Elements

Element Description

requestCaching

Controls the caching mechanism for network requests.

Remarks

The value for the policyLevel attribute is either BypassCache or Default.

Values for the maximumAge, maximumStale, and minimumFresh elements are either an explicit time interval with a format of d.hh:mm:ss (days, hours, minutes, and seconds), or the constants minValue or maxValue, as appropriate.

Configuration Files

This element can be used in the application configuration file or the machine configuration file (Machine.config).

Example

The following code example shows how to specify a minimum fresh time of six hours, a maximum age time of two days, and a maximum stale time of four hours.

<configuration>
  <system.net>
    <requestCaching>
      <defaultHttpCachePolicy>
        <set minimumFresh="0.06:00:00" />
        <set maximumAge  ="2.00:00:00" />
        <set maximumStale="0.04:00:00" />
      </defaultHttpCachePolicy>
    </requestCaching>
  </system.net>
</configuration>

See Also

Reference

Network Settings Schema
System.Net.Cache
WebRequest
RequestCacheLevel