HttpRequestCachePolicy.Level Property

Gets the HttpRequestCacheLevel value that was specified when this instance was created.

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

public HttpRequestCacheLevel Level { get; }

Property Value

Type: System.Net.Cache.HttpRequestCacheLevel
A HttpRequestCacheLevel value that specifies the cache behavior for resources that were obtained using HttpWebRequest objects.

Applications typically use Default as their cache policy level. The CachePolicy property, if not null, determines the cache policy in effect for a request. The default policy for the application domain can be set using the DefaultCachePolicy property or by settings in the machine or application configuration files. For more information, see <requestCaching> Element (Network Settings).

The following code example demonstrates displaying the value of this property.

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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft