Search code examples
asp.net-mvccachingdurationoutputcache

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?


Solution

  • 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.