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?

3
  • The default value of duration is "0" Commented Apr 22, 2016 at 7:09
  • So if Duration value is 0, its like we are not caching? Commented Apr 22, 2016 at 7:12
  • yes, that it is. 0 means no caching. Commented Apr 22, 2016 at 7:15

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.