Performance Issue when using RazorEngine.Razor.SetTemplateService

Mar 10, 2013 at 6:59 PM
Hi,

I noticed that if I use a base template for my razor views, the views don't get cached and are always begin parsed from scratch.

This is the code i am using:
// Set razor engine base template
                    var config = new RazorEngine.Configuration.TemplateServiceConfiguration
                    {
                        BaseTemplateType = typeof(MyTemplateBase<>)
                    };

                    using (var service = new TemplateService(config))
                    {
                        RazorEngine.Razor.SetTemplateService(service);
                        // Parse the template and also save it to cache
                        m_content.Text = RazorEngine.Razor.Parse(myTemplate, myModel, myCacheName);
                    }
This code runs on every request, and I think that is the problem.

Can someone point me in the right direction?

Thanks,
Robert
Mar 11, 2013 at 12:25 PM
Edited Mar 11, 2013 at 12:26 PM
I found the solution, I just moved the code that sets the template service to App_Start in global.asax and now everything works great :)