RazorEngine 中的模板是如何缓存的? [英] How are templates in RazorEngine cached?

查看:89
本文介绍了RazorEngine 中的模板是如何缓存的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你调用RazorEngine.Razor.Compile()时,编译后的模板存储在哪里?

When you call RazorEngine.Razor.Compile(), where is the compiled template stored?

重新启动程序后是否可用?如果内存不足,会不会被dump?

Is it available after the programs been restarted? If there is a memory shortage, will it be dumped?

我在 ASP.NET 中使用 RazorEngine(MVC)项目.应用重启后,预编译的模板是否可用?

I am using RazorEngine in an ASP.NET (MVC) project. Will the precompiled templates be available after the application restarts?

将它们存储在 HttpContext.Cache 中对我来说更有意义吗?如果我这样做了,那么使用绕过内部缓存的不同函数(除了Compile)是否更有意义?有没有办法执行 ITemplate 并只传递一个模型?

Would it make more sense for me to store them in the HttpContext.Cache? If I did, then would it make more sense to use a different function (other than Compile) that bypasses the internal cache? Is there a way to execute an ITemplate and just pass it a model?

RazorEngine.Razor.Parse() 做任何缓存吗?还是每次都要重新编译模板?

Does RazorEngine.Razor.Parse() do any caching? Or is the template recompiled each time?

推荐答案

目前,在 RazorEngine 编译模板后,它们被加载到内存中.这些程序集仅保留在内存中,不会超过应用程序的生命周期.

Currently, after the RazorEngine compiles the templates, they are loaded into memory. These assemblies persist in memory only and do not continue beyond the lifetime of the application.

我正在考虑添加对将这些程序集编译为文件的支持,但这将是未来的版本.

I am considering adding in support for compiling these assemblies to files, but that'll be a future version.

如果您调用 Razor.Parse 并传入模板的名称,它将尝试

If you call Razor.Parse and pass in a name for the template, it will attempt to

  1. 检查内存中程序集的缓存以查找同名程序集.
  2. 无效模板内容的缓存已更改.
  3. 缓存新编译的模板.

这篇关于RazorEngine 中的模板是如何缓存的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆