Skip to content

Support mustache template caching #20706

Closed as not planned
Closed as not planned

Description

@hookumsnivy

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.

Activity

  1. philwebb commented on Apr 15, 2020

    @philwebb
    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.

  2. added and removed
    status: waiting-for-triageAn issue that has not yet been triaged. Contributions will not be accepted.
    on Apr 15, 2020
  3. added this to the General Backlog milestone on Apr 15, 2020
  4. hookumsnivy commented on May 4, 2020

    @hookumsnivy
    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.

  5. snicoll commented on Nov 2, 2026

    @snicoll
    Member

    Closing in favor of PR #52398

  6. removed this from the General Backlog milestone on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions