ערוך

שתף באמצעות


RequestCachePolicy Constructors

Definition

Initializes a new instance of the RequestCachePolicy class.

Overloads

RequestCachePolicy()

Initializes a new instance of the RequestCachePolicy class.

RequestCachePolicy(RequestCacheLevel)

Initializes a new instance of the RequestCachePolicy class. using the specified cache policy.

RequestCachePolicy()

Source:
RequestCachePolicy.cs
Source:
RequestCachePolicy.cs
Source:
RequestCachePolicy.cs

Initializes a new instance of the RequestCachePolicy class.

public:
 RequestCachePolicy();
public RequestCachePolicy ();
Public Sub New ()

Examples

The following example demonstrates calling this constructor.

static WebResponse^ GetResponseUsingCacheDefault( Uri^ uri )
{
   // Set  the default cache policy level for the "http:" scheme.
   RequestCachePolicy^ policy = gcnew RequestCachePolicy;

   // Create the request.
   WebRequest^ request = WebRequest::Create( uri );
   request->CachePolicy = policy;
   WebResponse^ response = request->GetResponse();
   Console::WriteLine( L"Policy level is {0}.", policy->Level );
   Console::WriteLine( L"Is the response from the cache? {0}", response->IsFromCache );
   return response;
}
public static WebResponse GetResponseUsingCacheDefault(Uri uri)
{
    // Set  the default cache policy level for the "http:" scheme.
    RequestCachePolicy policy = new RequestCachePolicy();
    // Create the request.
    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;
}

Remarks

This constructor initializes the Level property to Default.

See also

Applies to

RequestCachePolicy(RequestCacheLevel)

Source:
RequestCachePolicy.cs
Source:
RequestCachePolicy.cs
Source:
RequestCachePolicy.cs

Initializes a new instance of the RequestCachePolicy class. using the specified cache policy.

public:
 RequestCachePolicy(System::Net::Cache::RequestCacheLevel level);
public RequestCachePolicy (System.Net.Cache.RequestCacheLevel level);
new System.Net.Cache.RequestCachePolicy : System.Net.Cache.RequestCacheLevel -> System.Net.Cache.RequestCachePolicy
Public Sub New (level As RequestCacheLevel)

Parameters

level
RequestCacheLevel

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

Exceptions

level is not a valid RequestCacheLevel.value.

Examples

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

static WebResponse^ GetResponseFromCache( Uri^ uri )
{
   RequestCachePolicy^ policy = gcnew RequestCachePolicy( RequestCacheLevel::CacheOnly );
   WebRequest^ request = WebRequest::Create( uri );
   request->CachePolicy = policy;
   WebResponse^ response = request->GetResponse();
   Console::WriteLine( L"Policy level is {0}.", policy->Level );
   Console::WriteLine( L"Is the response from the cache? {0}", response->IsFromCache );
   return response;
}
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;
}

Remarks

This constructor initializes the Level property to level.

The RequestCacheLevel value controls whether caching is enabled, and when the cache can be used. For additional information, see the RequestCacheLevel documentation.

See also

Applies to