You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the JMustache docs, all the necessary classes are thread safe with the caveat that if you customize any classes they also have to be thread safe.
Currently instances of the MustacheView class can be cached, but not the result of compilation. Every time the view is rendered in renderMergedTemplateModel, the resource gets loaded, parsed and compiled into a Template before rendering. If there was an option to cache the compiled form, perhaps with a pluggable caching implementation, we wouldn't need to load and compile on every request. Admittedly I didn't do any performance testing, but it seems like it should be beneficial.
While I'm on the subject of the MustacheView class, it strikes me as odd that it uses a getApplicationContext().getResource(...) to get the resource instead of a MustacheResourceTemplateLoader instance. After all, when using partials, it will load the partial using the MustacheResourceTemplateLoader.
Internally the mustache library uses a TemplateLoader instance that returns a Reader object. Since the mustache library uses that to load partials, it seems odd to me that the spring doesn't use that same object to load the main template as well. To think of it another way, the main template for your view is going to be pulled via spring's ResourceLoader and any partials are going to be pulled by via JMustache's TemplateLoader. It's just not consistent.
The auto configuration for Mustache does however set up a TemplateLoader that uses the Resource loader. My thought was why not use the TemplateLoader for both.
Activity
philwebb commentedon Apr 15, 2020
Can you expand on this a bit more? I'm not sure we can use the
TemplateLoadersince we need to resolve a URL inMustacheView.hookumsnivy commentedon May 4, 2020
Internally the mustache library uses a TemplateLoader instance that returns a Reader object. Since the mustache library uses that to load partials, it seems odd to me that the spring doesn't use that same object to load the main template as well. To think of it another way, the main template for your view is going to be pulled via spring's ResourceLoader and any partials are going to be pulled by via JMustache's TemplateLoader. It's just not consistent.
The auto configuration for Mustache does however set up a TemplateLoader that uses the Resource loader. My thought was why not use the TemplateLoader for both.
snicoll commentedon Nov 2, 2026
Closing in favor of PR #52398