Razor 页面 HTML 通过 RazorLight.NetCore3 模板键渲染

Razor Page HTML Rendering via RazorLight.NetCore3 Template Key

我最近集成了这个用于 Razor 页面渲染的 RazorLight 包。在使用时,我注意到必须定义一个模板键。这个模板密钥究竟是什么以及它有什么作用?

 var result = await engine.CompileRenderStringAsync("Template", content, model);

这里,第一个参数采用模板键。如果我使用不同的模板,那么我应该使用相同的密钥还是不同的密钥?

What actually this template key is and what it does?

If i use a different template, then should i use the same key or different?

当我们从字符串创建模板时,每个模板都应该有一个与之关联的 templateKey,这样我们就可以 re-run 使用此键的缓存模板。并且 templateKey 应该是唯一的。

string result = await engine.CompileRenderStringAsync("templateKey_here", template, model);

//...

var cacheResult = engine.Handler.Cache.RetrieveTemplate("templateKey_here");

关于RazorLight的概念和使用的更多信息,请查看以下内容link:

https://github.com/whyseco/RazorLight