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

1

6

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?

Flavor answered 22/4, 2016 at 7:2 Comment(3)
The default value of duration is "0"Lecturer
So if Duration value is 0, its like we are not caching?Flavor
yes, that it is. 0 means no caching.Lecturer
R
3

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.

Ruder answered 22/4, 2016 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.