Udostępnij za pośrednictwem


Cache Policy

A cache policy defines rules that are used to determine whether a request can be satisfied using a cached copy of the requested resource. Applications specify client cache requirements for freshness, but the effective cache policy is determined by the client cache requirements, the server's content expiration requirements, and the server's revalidation requirements. The interaction of client cache policy and server requirements always results in the most conservative cache policy, to help ensure that the freshest content is returned to the client application.

Cache policies are either location-based or time-based. A location-based cache policy defines the freshness of cached entries based on where the requested resource can be taken from. A time-based cache policy defines the freshness of cached entries using the time the resource was retrieved, headers returned with the resource, and the current time. Most applications can use the default time-based cache policy, which implements the caching policy specified in RFC 2616, available at http://www.ietf.org.

The classes described in the following table are used to specify cache policies.

Class name

Description

HttpRequestCachePolicy

Represents location-based and time-based cache policies for resources requested using HttpWebRequest objects.

RequestCachePolicy

Represents location-based cache policies or the Default time-based cache policy for resources requested using WebRequest objects.

HttpCacheAgeControl

Specifies values used to create time-based HttpRequestCachePolicy objects.

HttpRequestCacheLevel

Specifies values used to create location-based and time-based HttpRequestCachePolicy objects.

RequestCacheLevel

Specifies values used to create location-based or the Default time-based RequestCachePolicy objects.

You can define a cache policy for all requests made by your application or for individual requests. When you specify both an application-level cache policy and a request-level cache policy, the request-level policy is used. You can specify an application-level cache policy programmatically or by using the application or machine configuration files. For more information, see <requestCaching> Element (Network Settings).

To create a cache policy, you must create a policy object by creating an instance of the RequestCachePolicy or HttpRequestCachePolicy class. To specify the policy on a request, set the request's CachePolicy property to the policy object. When setting an application-level policy programmatically, set the DefaultCachePolicy property to the policy object.

For code examples that demonstrate creating and using cache policies, see Configuring Caching in Network Applications.

See Also

Concepts

Location-Based Cache Policies

Time-Based Cache Policies

Configuring Caching in Network Applications

Other Resources

Cache Management for Network Applications