I am using RazorEngine
to parse templates, using the below:
我正在使用RazorEngine解析模板,使用以下内容:
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).
首先,如果我没有将第三个参数指定为'cache',那么对这个方法的任何调用都需要500到1000毫秒,这很常见,因为这个问题被频繁调用。一旦传递该参数,第一次需要500-1000ms,但任何后续调用都需要可忽略的时间(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.
这是在Asp.Net MVC Web应用程序的上下文中执行的。但是,一旦刷新请求,第一次再次需要500-1000ms。
Any ideas why it takes so long, and what can be done ?
任何想法为什么需要这么长时间,可以做些什么?
I am using RazorEngine 3.2.0.0, and .Net 4.5.
我使用的是RazorEngine 3.2.0.0和.Net 4.5。
2 个解决方案
#1
1
The request takes a long time because the razor page must be compiled...
请求需要很长时间,因为必须编译剃刀页面...
Read this Precompiling razor page
阅读此预编译剃须刀页面
Hi
你好
#2
0
The issue was the third parameter - cacheName
. This must be a unique cache key, per unique template.
问题是第三个参数 - cacheName。每个唯一模板必须是唯一的缓存键。
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.
问题是我只使用一个模板进行单元测试,但在实际环境中,模板正在发生变化。缓存名称密钥是静态的,因此模板缓存始终无效。
#1
1
The request takes a long time because the razor page must be compiled...
请求需要很长时间,因为必须编译剃刀页面...
Read this Precompiling razor page
阅读此预编译剃须刀页面
Hi
你好
#2
0
The issue was the third parameter - cacheName
. This must be a unique cache key, per unique template.
问题是第三个参数 - cacheName。每个唯一模板必须是唯一的缓存键。
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.
问题是我只使用一个模板进行单元测试,但在实际环境中,模板正在发生变化。缓存名称密钥是静态的,因此模板缓存始终无效。