使用缓存配置文件缓存ChildActions将无法正常工作? [英] Caching ChildActions using cache profiles won't work?

查看:155
本文介绍了使用缓存配置文件缓存ChildActions将无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用缓存配置文件在我的MVC应用程序缓存孩子的行为,但我得到一个异常:时长必须为正数

I'm trying to use cache profiles for caching child actions in my mvc application, but I get an exception: Duration must be a positive number.

我的web.config文件看起来是这样的:

My web.config looks like this:

<caching>
      <outputCache enableOutputCache="true" />
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="TopCategories" duration="3600" enabled="true" varyByParam="none" />
        </outputCacheProfiles>
      </outputCacheSettings>
</caching>

和我的孩子动作是这样的:

And my child action something like this:

[ChildActionOnly]
[OutputCache(CacheProfile = "TopCategories")]
//[OutputCache(Duration = 60)]
public PartialViewResult TopCategories()
{
    //...
    return PartialView();
}

内部的视图我就叫 @ Html.RenderAction(TopCategories,类别)

不过,我得到一个错误:
异常详细信息:System.InvalidOperationException:时长必须为正数

But I get an error: Exception Details: System.InvalidOperationException: Duration must be a positive number.

如果我不使用缓存配置文件它的工作原理。有一个想法,有什么问题呢?

If I don't use cache profile it works. Have an idea what's the problem?

推荐答案

我做了一个<一挖一些href=\"http://stackoverflow.com/questions/4797968/asp-net-mvc-3-partial-page-output-caching-not-honoring-config-settings/4800140#4800140\">related问题看着MVC 3来源,他们绝对不支持以外的任何属性的持续时间的VaryByParam 。他们目前执行的主要缺陷是,如果你不提供这些任何一个,你会得到一个异常,告诉您该供应,而不是一个异常的说,你想用的是不支持的。另一个主要问题是,他们将缓存,即使你在web.config中,它似乎真的跛,而不是正确的关闭缓存。

I did some digging on a related question and looking at mvc 3 source, they definitely don't support any attribute other than Duration and VaryByParam. The main bug with their current implementation is that if you don't supply either one of these you will get an exception telling you to supply that, instead of an exception say that what you tried to use is not supported. The other major issue was that they will cache even if you turn off caching in the web.config, which seems really lame and not right.

我与它所有的最大的问题是,他们使用这两种观点并局部视图的工作方式相同的属性,但实际上它可能应该是2个不同的属性,因为局部的观点是如此有限,不同的行为很多的,至少在它的当前实施

The biggest issue I had with it all is that they are using the same attribute which works in both views and partial views, but in reality it should probably be 2 different attributes since the partial view is so limited and behaves a lot differently, at least in it's current implementation.

这篇关于使用缓存配置文件缓存ChildActions将无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆