Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mustache template caching #20706

Open
hookumsnivy opened this issue Mar 28, 2020 · 2 comments
Open

Support mustache template caching #20706

hookumsnivy opened this issue Mar 28, 2020 · 2 comments
Labels
type: enhancement A general enhancement

Comments

@hookumsnivy
Copy link

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 28, 2020
@philwebb
Copy link
Member

it strikes me as odd that it uses a getApplicationContext().getResource(...) to get the resource instead of a MustacheResourceTemplateLoader instance.

Can you expand on this a bit more? I'm not sure we can use the TemplateLoader since we need to resolve a URL in MustacheView.

@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 15, 2020
@philwebb philwebb added this to the General Backlog milestone Apr 15, 2020
@hookumsnivy
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants