HttpRequestCachePolicy Constructor ()


Initializes a new instance of the HttpRequestCachePolicy class.

Namespace:   System.Net.Cache
Assembly:  System (in System.dll)

public HttpRequestCachePolicy()

This constructor initializes the Level property to Default.

The following code example demonstrates setting the cache policy using this constructor.

public static WebResponse GetResponseUsingCacheDefault(Uri uri)
    // Set  the default cache policy level for the "http:" scheme.
    RequestCachePolicy policy = new RequestCachePolicy();
    // Create the request.
    WebRequest request = WebRequest.Create(uri);
    request.CachePolicy = policy;
    WebResponse response = request.GetResponse();
    Console.WriteLine("Policy level is {0}.", policy.Level.ToString());
    Console.WriteLine("Is the response from the cache? {0}", response.IsFromCache);  

    return response;

.NET Framework
Available since 2.0
Return to top