This documentation is archived and is not being maintained.

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 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.

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 ;

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 ;