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.
source share