HttpRequestCachePolicy Constructor (HttpCacheAgeControl, TimeSpan, 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 maximum age, age control value, and time value.

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

public HttpRequestCachePolicy(
	HttpCacheAgeControl cacheAgeControl,
	TimeSpan maxAge,
	TimeSpan freshOrStale


Type: System.Net.Cache.HttpCacheAgeControl

An HttpCacheAgeControl value.

Type: System.TimeSpan

A TimeSpan value that specifies the maximum age for resources.

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 is not valid.

The cacheAgeControl value is used to interpret the meaning of the freshOrStale parameter value and set the associated property. For example, when you specify MaxStale, the MaxStale property is set to the value of the freshOrStale parameter. When you specify MaxAgeAndMaxStale, the MaxAge property is set using the value of the maxAge parameter and the MaxStale property is set using the value of the freshOrStale parameter.

Note that unless you specify MaxAgeAndMaxStale or MaxAgeAndMinFresh, the MaxAge property is not set.

This constructor initializes the Level property to Default.

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

public static HttpRequestCachePolicy CreateFreshAndAgePolicy(TimeSpan freshMinimum, TimeSpan ageMaximum)
    HttpRequestCachePolicy policy = 
        new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAgeAndMinFresh, ageMaximum, freshMinimum); 
    return policy; 

.NET Framework
Available since 2.0
Return to top