asp.net MVC OutputCache属性的默认持续时间是多少?

时间:2016-04-22 07:02:01

标签: asp.net-mvc caching duration outputcache

我们正在使用MVC outputcache属性,如下所示

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

此处持续时间的默认值是什么?

1 个答案:

答案 0 :(得分:3)

持续时间属性在System.Web.Configuration.OutputCacheProfile.cs中初始化,这是相关代码:

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

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

将其设置为默认值-1,这是一个无效值。持续时间属性的文档提到:'持续时间必须在使用配置文件的页面的配置文件或指令中定义。'

因此,实际上没有(有效)默认值,您需要指定它。