Udostępnij za pośrednictwem


How to: Set the Default Time-Based Cache Policy for an Application

The default time-based cache policy allows an application to have its cache behavior defined by the headers sent with the cached resource and the cache behavior defined in sections 13 and 14 of RFC 2616, available at http://www.ietf.org. This is the appropriate cache behavior for most applications.

To set the default automatic policy for an application

  1. Create a default time-based policy object.

  2. Set the policy object as the default for the application domain.

Example

The two examples in this section produce identical policies.

The following example creates a default time-based policy and sets it as the default for the application domain.

public static void SetDefaultTimeBasedPolicy ()
{
    HttpRequestCachePolicy policy = new HttpRequestCachePolicy ();
    HttpWebRequest.DefaultCachePolicy = policy ;
}
Public Shared Sub SetDefaultTimeBasedPolicy ()
    Dim policy = New HttpRequestCachePolicy ()
    HttpWebRequest.DefaultCachePolicy = policy
End Sub

You can also create the default time-based cache policy using the RequestCachePolicy class as shown in the following example:

public static void SetDefaultTimeBasedPolicy2()
{
    RequestCachePolicy policy = new RequestCachePolicy ();
    HttpWebRequest.DefaultCachePolicy = policy ;
}
Public Shared Sub SetDefaultTimeBasedPolicy2()
    Dim policy As New RequestCachePolicy()
    HttpWebRequest.DefaultCachePolicy = policy
End Sub

See Also

Concepts

Cache Policy

Location-Based Cache Policies

Time-Based Cache Policies

Reference

<requestCaching> Element (Network Settings)

Other Resources

Cache Management for Network Applications