HttpRequestCachePolicy Constructor (HttpCacheAgeControl, TimeSpan)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on 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


Type: System.Net.Cache.HttpCacheAgeControl

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

Type: System.TimeSpan

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

Exception Condition

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