Level Property
Collapse the table of content
Expand the table of content

RequestCachePolicy.Level Property

Note: This property is new in the .NET Framework version 2.0.

Gets the RequestCacheLevel value specified when this instance was constructed.

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

public RequestCacheLevel Level { get; }
/** @property */
public RequestCacheLevel get_Level ()

public function get Level () : RequestCacheLevel

Property Value

A RequestCacheLevel value that specifies the cache behavior for resources obtained using WebRequest objects.

Applications typically use Default as their cache policy level. Using the Default level, the effective cache policy is determined by the current cache policy and the age of the content in the cache. The WebRequest.CachePolicy property, if not a null reference (Nothing in Visual Basic), determines the cache policy in effect for a request.

The default policy for the application domain can be set using the DefaultCachePolicy or the application or machine configuration file. For more information, see requestCaching Element (Network Settings).

The following code example creates a CacheOnly policy and sends a request.

public static WebResponse GetResponseFromCache(Uri uri)
{
     RequestCachePolicy policy = 
        new  RequestCachePolicy( RequestCacheLevel.CacheOnly);
    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;
    
} 

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

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2016 Microsoft