HttpRequestCachePolicy.Level Property

Definition

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

C#
public System.Net.Cache.HttpRequestCacheLevel Level { get; }

Property Value

A HttpRequestCacheLevel value that specifies the cache behavior for resources that were obtained using HttpWebRequest objects.

Examples

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

C#
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;
}

Remarks

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

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1