Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default Duration of asp.net MVC OutputCache attribute?

We are using MVC outputcache attribute, as shown below

[OutputCache(Location = System.Web.UI.OutputCacheLocation.Server, Duration = 60 * 60 * 12, VaryByParam = "staticDataTypes;customerSubscriptionId")]

Here what is the default value of Duration?

like image 991
Sparrow Avatar asked Apr 22 '16 07:04

Sparrow


1 Answers

The Duration property is initialized in System.Web.Configuration.OutputCacheProfile.cs, here's the relevant code:

_propDuration = new ConfigurationProperty("duration", typeof(int), -1, 
                                          ConfigurationPropertyOptions.None); 

and

[ConfigurationProperty("duration", DefaultValue = -1)]
public int Duration {
    get { 
         return (int)base[_propDuration];
    } 
    set { 
        base[_propDuration] = value;
    } 
}

Which sets it to a default of -1 which is an invalid value. Documentation for the Duration property mentions: 'The Duration must be defined in either the profile or the directive of a page using the profile.'

So, there's actually no (valid) default value, you are required to specify it.

like image 151
Ton Plooij Avatar answered Nov 15 '22 11:11

Ton Plooij