Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

RequestCachePolicy Class

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

Defines an application's caching requirements for resources obtained by using WebRequest objects.

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

public class RequestCachePolicy
public class RequestCachePolicy
public class RequestCachePolicy

You can specify a default cache policy for your application by using the DefaultCachePolicy property or the application or machine configuration files. For more information, see requestCaching Element (Network Settings).

You can specify the cache policy for an individual request by using the CachePolicy property.

Caching for Web services is not supported.

The following code example creates a policy with Level set to CacheOnly, and uses it to set the cache policy of a WebRequest.

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

System.Object
  System.Net.Cache.RequestCachePolicy
     System.Net.Cache.HttpRequestCachePolicy
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.