I am using RazorEngine
to parse templates, using the below:
string parsedText = Razor.Parse(template, model, "cache");
First of all, if I didn't specify the 3rd parameter as 'cache', any calls to this method will take 500 - 1000ms, which is a lot given this is called quite frequently. Once you pass that parameter, the first time it takes 500 - 1000ms, but any subsequent calls take neglible time (0-1ms).
This is executed in the context of an Asp.Net MVC web-application. However, once the request is refreshed, this again takes 500 -1000ms for the first time.
Any ideas why it takes so long, and what can be done ?
I am using RazorEngine 3.2.0.0, and .Net 4.5.
The issue was the third parameter - cacheName
. This must be a unique cache key, per unique template.
I changed this to a different one each time based on the template, and it is now working perfectly and blazingly fast.
The issue was that I was unit testing it with just one template, however in the actual environment, the template was changing. The cache name key was static, hence the template cache was being invalidated all the time.