This documentation is archived and is not being maintained.

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;
}
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(S"Policy level is {0}.", __box(policy->Level));
        Console::WriteLine(S"Is the response from the cache? {0}", __box(response->IsFromCache));  

        return response;
    }

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: