IVirtualPathFactory registration causes BuildManager call for every _Layout Page

May 16, 2013 at 10:03 AM
Edited May 16, 2013 at 10:11 AM
I set my layout inside my .cshtml pages like this:
@{
    Layout = "~/Views/Shared/_LayoutMicroPedi.cshtml";
}
With the default RazorGeneratorMvcStart file this code is executed (to make sure _ViewStart works properly):

VirtualPathFactoryManager.RegisterVirtualPathFactory(engine);

However this causes calls to IVirtualPathFactory.CreateInstance for every page that uses a Layout (no other virtualpaths seem to ever reach this method). The default setting for PreemptPhysicalFiles is false so this means the following code is executed for every page with a layout.
  return BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebPageRenderingBase));
That seems to kind of defeat the whole caching mechanism.

I'm also pretty confused when I'm supposed to use PreemptPhysicalFiles vs. UsePhysicalViewsIfNewer.

I'm not even using WebStart (or multiple DLLs) so I just removed this 'RegisterVirtualPathFactory' method.

Would be interested to hear somebody elses thoughts on this.
Coordinator
May 16, 2013 at 4:26 PM
There's some documentation of what the two properties mean here - https://razorgenerator.codeplex.com/wikipage?title=Using%20RazorGenerator.Mvc&referringTitle=Documentation

I'm not entirely sure what you mean by caching mechanism. The code path that we have is a near clone of of the Razor ViewEngine in System.Web.Mvc.