我正在使用ASP.NET MVC3.
我在控制器方法上使用了输出缓存.
我在控制器方法上使用了输出缓存.
[OutputCache(Duration = 3660,varyByParam = "none")] public ActionResult Index() { some code; return View(); }
我想在输出缓存中使用一些静态变量或其他东西来设置动态持续时间.
我怎样才能做到这一点?
解决方法
我将继承OutputCache属性并在那里设置持续时间:
public static class CacheConfig { public static int Duration = 36600; } public class MyOutputCacheAttribute : OutputCacheAttribute { public MyOutputCacheAttribute() { this.Duration = CacheConfig.Duration; } } [MyOutputCache(varyByParam = "none")] public ActionResult Index() { return View(); }
然后,您可以动态更改持续时间,并通过CacheConfig.Duration全局更改
如果需要,您仍然可以覆盖每个操作的全局设置:
[MyOutputCache(Duration = 100,varyByParam = "none")] public ActionResult OtherAction() { return View(); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。