Donut Hole Caching - Exclude 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 also cached. I would like to exclude MiniProfiler output from caching (donut hole), but I'm not sure how I can exclude a call, for example MiniProfiler.RenderIncludes ().

Anyone who knows how I can do this?

+6
source share
1 answer

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

First, to enable caching of holes in the donut, I use:

http://mvcdonutcaching.codeplex.com/

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

Given the above, you can remove @using StackExchange.Profiling; from the layout page. Then you can replace:

 @MiniProfiler.RenderIncludes() 

FROM

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

I created a DoNotCache controller, so all of my non-cached items are merged, but this is not required, and you can put this action in any controller.

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

And then the view itself looks like this:

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

This ensures that MiniProfiler results are displayed when needed, and are not cached during production, even where you use the DonutOutputCache annotation.

+6
source

All Articles