RequestCachePolicy Class
Defines an application's caching requirements for resources obtained by using WebRequest objects.
Assembly: System (in System.dll)
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(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.