Export (0) Print
Expand All

RequestCachePolicy.Level Property

Gets the RequestCacheLevel value specified when this instance was constructed.

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

public RequestCacheLevel Level { get; }

Property Value

Type: System.Net.Cache.RequestCacheLevel
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 null, 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;

} 

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft