我正在使用Nuget的awesom MVCDonutCaching软件包来缓存整个页面,同时保留某些未缓存的部分。这个过程很简单,一切正常:
我正在缓存如下:
[DonutOutputCache(CacheProfile = "FiveMins")]
public ActionResult Index()
{
return View();
}
对于我的页面部分,我不想缓存我正在执行以下操作:
@Html.Action("HeaderLinks","Home", true)
这样可以正常工作,实际上页面的大部分都被缓存但是我的标题链接 - 如果用户未登录则显示登录按钮的上下文敏感链接,如果是,则显示其用户名等 - 未缓存。到目前为止一切正常。
我遇到的问题是headerlinks属于主/布局页面并且全面使用 - 无论Action是否设置了DonutOutputCache属性。当我创建另一个动作时,让我们称它为“关于我们”,没有甜甜圈缓存属性我根本看不到我的标题链接
public ActionResult AboutUs()
{
return View();
}
查看源代码,我看到以下内容
<!--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>
#-->
显然,在上面的例子中,由甜甜圈缓存库生成 - 链接部分被一些注释的XML替换。
简而言之,我的问题是:是否可以使用此库重复使用相同的子操作,无论父操作是否使用圆环缓存?
任何帮助都将不胜感激。
答案 0 :(得分:4)
目前,您需要将Html.Action与DonutOutputCache动作过滤器一起使用,以便渲染圆环孔。如果您在没有DonutOutputCache的情况下使用Html.Action,您将看到上面概述的占位符注释。
这是一个疏忽,将在下一个版本中解决。