jdiamond/Nustache — Issue #24: Need caching around GetTemplate
Author: phillipb
Created: 2012-03-05 14:37:19+00:00
State: open

I think you know this already based on the comments in the code, but after running some performance test, definitely need caching in GetTemplate method of NustacheView.

Something like this :
private Template GetTemplate(string path)
{
if (_controllerContext.HttpContext.Cache["tmp_" + path] != null)
{
return (Template)_controllerContext.HttpContext.Cache["tmp_" + path];
}

var templatePath = _controllerContext.HttpContext.Server.MapPath(path);

var templateSource = File.ReadAllText(templatePath);
templateSource = Razor.Parse(templateSource, new { Request = _controllerContext.HttpContext.Request});

var template = new Template();
template.Load(new StringReader(templateSource));

CacheDependency dep = new CacheDependency(templatePath);

_controllerContext.HttpContext.Cache.Insert("tmp_" + path, template, dep);

return template;
}