HttpRequestCachePolicy Constructor (HttpCacheAgeControl, TimeSpan)

 
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.

Initializes a new instance of the HttpRequestCachePolicy class using the specified age control and time values.

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

public HttpRequestCachePolicy(
	HttpCacheAgeControl cacheAgeControl,
	TimeSpan ageOrFreshOrStale
)

Parameters

cacheAgeControl
Type: System.Net.Cache.HttpCacheAgeControl

One of the following HttpCacheAgeControl enumeration values: MaxAge, MaxStale, or MinFresh.

ageOrFreshOrStale
Type: System.TimeSpan

A TimeSpan value that specifies an amount of time. See the Remarks section for more information.

Exception Condition
ArgumentException

The value specified for the cacheAgeControl parameter cannot be used with this constructor.

The cacheAgeControl value defines the meaning of the ageOrFreshOrStale parameter value and is used to set the associated property. For example, when you specify MaxStale, the MaxStale property is set to the value of the ageOrFreshOrStale parameter.

This constructor initializes the Level property to Default.

The following code example demonstrates creating a cache policy based on minimum freshness.

public static HttpRequestCachePolicy CreateMinFreshPolicy(TimeSpan span)
{
    HttpRequestCachePolicy policy = 
        new HttpRequestCachePolicy(HttpCacheAgeControl.MinFresh, span); 
    Console.WriteLine("Minimum freshness {0}", policy.MinFresh.ToString());
    return policy;
} 

.NET Framework
Available since 2.0
Return to top
Show: