甜甜圈洞缓存 - 排除MiniProfiler.RenderIncludes [英] Donut hole caching - exclude MiniProfiler.RenderIncludes

查看:505
本文介绍了甜甜圈洞缓存 - 排除MiniProfiler.RenderIncludes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个装饰着的OutputCache 属性的ASP.NET MVC行动,但问题是,MiniProfiler输出缓存为好。我想排除缓存(甜甜圈洞)输出的MiniProfiler,但我不知道我怎么能像排除一个MiniProfiler.RenderIncludes()的调用。

I have an ASP.NET MVC action that is decorated with the OutputCache attribute, but the problem is that the MiniProfiler output is cached as well. I'd like to exclude the MiniProfiler output from the caching (donut hole), but I'm not sure how I can exclude a call like MiniProfiler.RenderIncludes().

任何人谁碰巧知道我该怎么做呢?

Anyone who happen to know how I can do this?

推荐答案

这是,如果在生产中使用MiniProfiler重要的一点。就好像一个页面的第一次访问是在哪里MiniProfiler启用了用户,所有后续请求将包括DOM的MiniProfiler结果(因为它们现在被高速缓存)。不仅将结果是不正确的(因为它们只考虑第一负载),但所有的参观者将能看到你的MiniProfiler结果。

This is an important point if using MiniProfiler in production. As if the first visit to a page is by a user where MiniProfiler is enabled, all subsequent requests will include the MiniProfiler results in the DOM (as they are now cached). Not only will the results be incorrect (as they only consider first load), but all visitors will be able to see your MiniProfiler results.

首先,使甜甜圈洞缓存,我正在使用的:

Firstly, to enable donut hole caching, I'm making use of:

HTTP://mvcdonutcaching.$c$cplex.com/

这允许您添加使用的OutputCache时将不被缓存的动作。

This allows you to add actions which will not be cached when using the OutputCache.

鉴于上述情况,你可以删除 @using StackExchange.Profiling; 从布局页。然后,您可以替换:

Given the above, you can remove @using StackExchange.Profiling; from your Layout page. You can then replace:

@MiniProfiler.RenderIncludes()

使用:

@Html.Action("MiniProfiler", "DoNotCache", excludeFromParentCache: true)

我已经创建了一个DoNotCache控制器,所以我所有的非缓存元素在一起,但这不是必需的,你可以放在任何控制器这个动作。

I have created a DoNotCache controller, so all my non-cacheable elements are together, but this is not required and you can place this action in any controller.

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

和则认为自己只是看起来像:

And then the view itself just looks like:

@using StackExchange.Profiling;
@{
    Layout = null;
}
@MiniProfiler.RenderIncludes()

这将确保MiniProfiler结果在适当的时候,即使在您使用 DonutOutputCache 标注的地方显示出来,并在生产中没有缓存。

This will ensure the MiniProfiler results are displayed when appropriate, and not cached in production even in places where you use the DonutOutputCache annotation.

这篇关于甜甜圈洞缓存 - 排除MiniProfiler.RenderIncludes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆