Op Englesch liesen Editéieren

Deelen iwwer


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.

C#
public RequestCachePolicy();

Examples

The following example demonstrates calling this constructor.

C#
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

.NET 10 an aner Versiounen
Produkt Versiounen
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

RequestCachePolicy(RequestCacheLevel)

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

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

C#
public RequestCachePolicy(System.Net.Cache.RequestCacheLevel level);

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.

C#
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

.NET 10 an aner Versiounen
Produkt Versiounen
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1