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

99封情书 提交于 2019-12-10 17:11:09

问题


I am using the awesom MVCDonutCaching package from Nuget in order to cache entire pages while leaving certain portions uncached. 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. 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.

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.


回答1:


Currently you are required to use the Html.Action together with the DonutOutputCache action filter in order to get the donut hole to render. If you use the Html.Action without the DonutOutputCache, you will see the placeholder comment that you have outlined above.

This is an oversight though and will be addressed in the next release.

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



来源:https://stackoverflow.com/questions/8466633/mvcdonutcaching-issues-with-child-action-when-parent-is-not-donut-cached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!