This project is read-only.

Caching of non-precompiled views on a consuming project?

Nov 12, 2012 at 6:20 AM

I have the precompiled views as a base template structure for multiple sites, but I wanted to override specific templates in specific consuming projects.  For instance a 3 column template in one project might have different element structures or CSS classes.  

This all worked well and I thought things were going great until I changed something in the precompiled view project.  IIS then ignores the overriding views in the consuming site and shows the precompiled view.  I've tried a few things and haven't figured it out.  I was wondering if this has been figured out by anyone?  

The only way to "fix" it is to change the overriding views and save them, since they're not precompiled they instantly work on browser refresh.  I would assume this has something to do with how the VirtualPathProvider decides to serve the views and it's coming down to a caching issue.

Nov 12, 2012 at 4:32 PM

I have added documentation around how you could configure the ViewEngine at One of the two scenarios under "Configuring the Views" should probably address your scenario. Let me know if neither helps and we can try and sort it out.

Nov 12, 2012 at 4:40 PM

The behavior you're seeing is strange, because changing the precompiled view project should update its assembly in bin, which in turn should restart the appdomain and cause all the views to be recompiled clean.

Nov 12, 2012 at 5:33 PM

I talked to Pranav, and the behavior is indeed explained by the page he pointed to, so please give that a read.

Nov 13, 2012 at 2:51 AM

Hey thanks for prompt the replies.  Yeah it's still not working, I noticed that it wasn't added to the global.asax but then figured out that you're using a library called WebActivator to auto run the start method in the RazorGeneratorMvcStart class.  Correct me if I'm wrong, just want to make sure that's what's happening and it's not just that I'm not calling it.

One thing I'm noticing in the code (which I was looking at last night) is that it does indeed have "UsePhysicalViewsIfNewer", which is exactly what's happening.

Just to be clear this is a .Net 4.5 project MVC4, I have the precompiledlibrary with the razorgenerator obviously referenced and the MVC project does not reference the library (meaning it does not have the RazorGeneratorMvcStart class), I've tried it both ways.  I've changed the following code in RazorGeneratorMvcStart to the following: 

var engine = new PrecompiledMvcEngine(typeof(RazorGeneratorMvcStart).Assembly) {
                UsePhysicalViewsIfNewer = HttpContext.Current.Request.IsLocal,
                PreemptPhysicalFiles = true

And it still behaves the same way, where it works until the precompiledviews are updated, then when I update the "physical" views it doesn't work anymore.

Nov 13, 2012 at 4:59 AM

Did you try the other bit about shuffling around the ViewEngines? Essentially what you're trying to achieve is to always let the Mvc's default engine to serve views if they are available which should work if you do so: 


ViewEngines.Engines.Insert(0, engine);


Nov 13, 2012 at 7:17 AM

Wow... that did it.  I tried that yesterday and it didn't work.  So the combo of adding: 

PreemptPhysicalFiles = true

and changing the line you suggested seems to have solved the problem!

Thanks a lot guys.