简体   繁体   English

MVCDonutCaching - 当父级未进行环形缓存时,子操作的问题

[英]MVCDonutCaching - Issues with child action when parent is not donut cached

I am using the awesom MVCDonutCaching package from Nuget in order to cache entire pages while leaving certain portions uncached. 我正在使用Nuget的awesom MVCDonutCaching包来缓存整个页面,同时保留某些未缓存的部分。 The process is simple and everything works as it should: 这个过程很简单,一切正常:

I am caching as follows: 我缓存如下:

[DonutOutputCache(CacheProfile = "FiveMins")]
public ActionResult Index()
{
  return View();
}

For the section of my page I do not wish to cache I am doing the following: 对于我的页面部分,我不想缓存我正在执行以下操作:

  @Html.Action("HeaderLinks","Home", true)

This works as it should and indeed the bulk of the page is cached but my header links - context sensitive links displaying a log on button if the user is not logged in, their username if they are, etc. - is not cached. 这应该工作,实际上页面的大部分是缓存但我的标题链接 - 上下文敏感链接显示登录按钮,如果用户没有登录,他们的用户名,如果他们是,等等 - 没有缓存。 So far everything works. 到目前为止一切正常。

The problem that I am having is that the headerlinks belong to a master/layout page and are used across the board - regardless of whether an Action has a DonutOutputCache attribute set or not. 我遇到的问题是headerlinks属于主/布局页面并且全面使用 - 无论Action是否设置了DonutOutputCache属性。 When I create another action, let's call it 'about us', without a donut caching attribute I do not see my header links at all 当我创建另一个动作时,让我们称它为“关于我们”,没有甜甜圈缓存属性我根本看不到我的标题链接

public ActionResult AboutUs()
{
  return View();
}

Looking at the source code I see the following 查看源代码,我看到以下内容

<!--Donut#
<ActionSettings xmlns="http://schemas.datacontract.org/2004/07/DevTrends.MvcDonutCaching" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ActionName>HeaderLinks</ActionName>
<ControllerName>Home</ControllerName>
<RouteValues xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringanyType>
<a:Key>Area</a:Key>
<a:Value i:type="b:string" xmlns:b="http://www.w3.org/2001/XMLSchema"/>
</a:KeyValueOfstringanyType>
</RouteValues>
</ActionSettings>
#-->

Obviously in the above example, which is generated by the donut caching library - the links section is replaced by some commented XML. 显然,在上面的例子中,由甜甜圈缓存库生成 - 链接部分被一些注释的XML替换。

My question in a nutshell is: is it possible with this library to reuse the same child action regardless of whether the parent action is using donut caching or not? 简而言之,我的问题是:无论父操作是否使用圆环缓存,该库是否都可以重用相同的子操作?

Any help would be appreciated. 任何帮助,将不胜感激。

Currently you are required to use the Html.Action together with the DonutOutputCache action filter in order to get the donut hole to render. 目前,您需要将Html.Action与DonutOutputCache动作过滤器一起使用,以便渲染圆环孔。 If you use the Html.Action without the DonutOutputCache, you will see the placeholder comment that you have outlined above. 如果您在没有DonutOutputCache的情况下使用Html.Action,您将看到上面概述的占位符注释。

This is an oversight though and will be addressed in the next release. 这是一个疏忽,将在下一个版本中解决。

see http://mvcdonutcaching.codeplex.com/workitem/2388 http://mvcdonutcaching.codeplex.com/workitem/2388

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM