是否有一个在MVC4 .net页面的web.config中设置缓存的持续时间?我有 :
[OutputCache(Duration = Convert.ToInt32(ConfigurationManager.AppSettings["cache.eventPage"]),VaryByParam = "Id")] public ActionResult....
哪个不会编译,因为
An attribute argument must be a constant expression,typeof expression or array creation expression of an attribute parameter type
我们有非常灵活的流量,并且希望能够在推出新版本的情况下非常快速地更改此值.这可能吗?
解决方法
你可以用
OutputCache profiles;在web.config中定义一个部分
<system.web> <caching> <outputCacheSettings> <outputCacheProfiles> <add name="CacheProfile1" duration="10" /> <!--10 seconds --> <add name="CacheProfile2" duration="3600" /> <!--one hour--> <add name="CacheProfileNone" duration="0" /> <!--disabled--> </outputCacheProfiles> </outputCacheSettings> </caching> </system.web>
通过您已经完成的属性在控制器操作方法上使用它.只需使用CacheProfile属性即可.
[OutputCache(CacheProfile = "CacheProfile1",VaryByParam = "Id")]
您可以为每个缓存方案创建不同的配置文件.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。