lar*_*rsw 6 asp.net-mvc donut-caching mvc-mini-profiler
我有一个使用该OutputCache属性修饰的ASP.NET MVC操作,但问题是MiniProfiler输出也被缓存.我想从缓存(圆环孔)中排除MiniProfiler输出,但我不确定如何排除像MiniProfiler.RenderIncludes()之类的调用.
谁碰巧知道我怎么做到这一点?
如果在生产中使用MiniProfiler,这一点非常重要.好像第一次访问页面是由启用了MiniProfiler的用户,所有后续请求都将在DOM中包含MiniProfiler结果(因为它们现在被缓存).结果不仅不正确(因为他们只考虑首次加载),但所有访问者都能看到您的MiniProfiler结果.
首先,为了实现甜甜圈洞缓存,我正在利用:
http://mvcdonutcaching.codeplex.com/
这允许您添加在使用OutputCache时不会缓存的操作.
鉴于上述情况,您可以@using StackExchange.Profiling;从"布局"页面中删除.然后你可以替换:
@MiniProfiler.RenderIncludes()
Run Code Online (Sandbox Code Playgroud)
附:
@Html.Action("MiniProfiler", "DoNotCache", excludeFromParentCache: true)
Run Code Online (Sandbox Code Playgroud)
我创建了一个DoNotCache控制器,因此我的所有非可缓存元素都在一起,但这不是必需的,您可以将此操作放在任何控制器中.
public ActionResult MiniProfiler()
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
然后视图本身看起来像:
@using StackExchange.Profiling;
@{
Layout = null;
}
@MiniProfiler.RenderIncludes()
Run Code Online (Sandbox Code Playgroud)
这将确保MiniProfiler结果在适当时显示,并且即使在使用DonutOutputCache注释的位置也不会在生产中缓存.
| 归档时间: |
|
| 查看次数: |
705 次 |
| 最近记录: |