我正在尝试使用缓存配置文件缓存我的mvc应用程序中的子操作,但我得到一个例外:持续时间必须是正数.
我的web.config看起来像这样:
<caching>
<outputCache enableOutputCache="true" />
<outputCacheSettings>
<outputCacheProfiles>
<add name="TopCategories" duration="3600" enabled="true" varyByParam="none" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
Run Code Online (Sandbox Code Playgroud)
而我的孩子的动作是这样的:
[ChildActionOnly]
[OutputCache(CacheProfile = "TopCategories")]
//[OutputCache(Duration = 60)]
public PartialViewResult TopCategories()
{
//...
return PartialView();
}
Run Code Online (Sandbox Code Playgroud)
我只是打电话给一个视图 @Html.RenderAction("TopCategories", "Category")
但是我收到一个错误:Exception Details:System.InvalidOperationException:Duration必须是一个正数.
如果我不使用缓存配置文件,它的工作原理.知道问题是什么?
我有一个简单的局部视图,我在主视图中渲染:
@Html.Action("All", "Template")
Run Code Online (Sandbox Code Playgroud)
在我的控制器上我有这个:
[OutputCache(CacheProfile = "Templates")]
public ActionResult All()
{
return Content("This stinks.");
}
Run Code Online (Sandbox Code Playgroud)
在我的配置中:
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<clear/>
<add name="Templates" duration="3600" varyByParam="none"/>
</outputCacheProfiles>
</outputCacheSettings>
<outputCache enableOutputCache="false" enableFragmentCache="false" />
</caching>
Run Code Online (Sandbox Code Playgroud)
这将在运行时失败,但有异常:
执行处理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper的子请求时出错
内在异常:
持续时间必须是正数
现在显然它没有拿起我的web.config设置,因为如果我将其更改为:
[OutputCache(Duration = 3600)]
Run Code Online (Sandbox Code Playgroud)
它会工作,而且在我的web.config通知我关掉enableOutputCache和enableFragmentCache,但它不支持这些设置.
奇怪的是,在普通视图中这些设置工作正常,那么部分视图是什么打破了这个呢?我错过了什么吗?顾说这应该工作得很好...... 总之,它是否应该尊重web.config中的缓存设置,如果没有,为什么不呢?