@Html.Action("All","Template")
在我的控制器上我有这个:
[OutputCache(CacheProfile = "Templates")] public ActionResult All() { return Content("This stinks."); }
在我的配置中:
<caching> <outputCacheSettings> <outputCacheProfiles> <clear/> <add name="Templates" duration="3600" varyByParam="none"/> </outputCacheProfiles> </outputCacheSettings> <outputCache enableOutputCache="false" enableFragmentCache="false" /> </caching>
这将在运行时失败,但有异常:
Error executing child request for handler ‘System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper
内在的例外:
Duration must be a positive number
现在显然它没有拿起我的web.config设置,因为如果我将其更改为:
[OutputCache(Duration = 3600)]
它会工作,但在我的web.config中也会注意到我关闭了enableOutputCache和enableFragmentCache,但是它没有遵循这些设置.
奇怪的是,在普通视图中这些设置工作正常,那么部分视图是什么打破了这个呢?我错过了什么吗? The Gu says this should work just fine…
简而言之,是否应该尊重web.config中的缓存设置,如果没有,为什么不呢?
解决方法
如何找出支持的内容超出了我的范围.因为除非你提供了一个持续时间和一个VaryByParam值,否则他们想抛出的异常会说永远不会抛出Unsupported Setting
这是代码的主要代码:
if (Duration <= 0) { throw new InvalidOperationException(MvcResources.OutputCacheAttribute_InvalidDuration); } if (String.IsNullOrWhiteSpace(VaryByParam)) { throw new InvalidOperationException(MvcResources.OutputCacheAttribute_InvalidVaryByParam); } if (!String.IsNullOrWhiteSpace(CacheProfile) || !String.IsNullOrWhiteSpace(SqlDependency) || !String.IsNullOrWhiteSpace(VaryByContentEncoding) || !String.IsNullOrWhiteSpace(VaryByHeader) || _locationWasSet || _noStoreWasSet) { throw new InvalidOperationException(MvcResources.OutputCacheAttribute_ChildAction_UnsupportedSetting); }
我不确定为什么在documentation中没有调用它,但即使它是api也应该清楚,或者至少抛出正确的异常.
简而言之,部分输出缓存有效,但不像你想要的那样.我将努力修复代码并尊重某些设置,如启用.
更新:
我修改了当前的实现,至少在我的情况下工作,尊重启用标志并允许来自web.config的缓存配置文件. Detailed in my blog post.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。