This project is read-only.

Performance Issue when using RazorEngine.Razor.SetTemplateService

Mar 10, 2013 at 7:59 PM

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))
                        // 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?

Mar 11, 2013 at 1:25 PM
Edited Mar 11, 2013 at 1: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 :)