Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

RequestCachePolicy.Level Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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
Available since 2.0
Return to top
Show:
© 2018 Microsoft