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

6
我们正在使用MVC输出缓存属性,如下所示。
[OutputCache(Location = System.Web.UI.OutputCacheLocation.Server, Duration = 60 * 60 * 12, VaryByParam = "staticDataTypes;customerSubscriptionId")]

这里的Duration的默认值是什么?

默认的持续时间值为"0"。 - Yogi
如果持续时间值为0,那么就像我们没有缓存一样? - Sparrow
是的,就是这样。0 表示不缓存。 - Yogi
1个回答

3
Duration属性在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,这是一种无效的值。Duration属性的文档提到:'必须在使用profile指令定义页面的profile或directive中定义Duration。'

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接