使用缓存配置文件缓存 ChildActions 不起作用?

编程入门 行业动态 更新时间:2024-10-13 08:18:12
本文介绍了使用缓存配置文件缓存 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", "Category")

Inside a view I just call @Html.RenderAction("TopCategories", "Category")

但我收到一个错误:异常详细信息: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?

推荐答案

我对 相关问题 并查看 mvc 3 源代码,它们绝对不支持 Duration 以外的任何属性和 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 不起作用?

本文发布于:2023-11-26 08:39:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   配置文件   不起作用   ChildActions

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!