Export (0) Print
Expand All

HttpRequestCachePolicy Constructor (HttpCacheAgeControl, TimeSpan, TimeSpan, DateTime)

Initializes a new instance of the HttpRequestCachePolicy class using the specified maximum age, age control value, time value, and cache synchronization date.

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

public HttpRequestCachePolicy(
	HttpCacheAgeControl cacheAgeControl,
	TimeSpan maxAge,
	TimeSpan freshOrStale,
	DateTime cacheSyncDate


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.  

Type: System.DateTime

A DateTime object that specifies the time when resources stored in the cache must be revalidated.

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 CacheSyncDate property to cacheSyncDate, and initializes the Level property to Default.

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

public static HttpRequestCachePolicy CreateFreshAndAgePolicy2(TimeSpan freshMinimum, TimeSpan ageMaximum, DateTime when)
    HttpRequestCachePolicy policy = 
        new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAgeAndMinFresh, ageMaximum, freshMinimum, when); 
    return policy;
    // For the following invocation:  
    // CreateFreshAndAgePolicy(new TimeSpan(5,0,0), new TimeSpan(10,0,0),); 
    // the output is: 
    // Level:Automatic  
    // AgeControl:MinFreshAndMaxAge  
    // MinFresh:18000  
    // MaxAge:36000

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft