Handlebars Java Precompiled Template Cache Sizing and Trusted Source Boundaries
0 reputation · 05 Jul 2021, 16:45 UTC
In current Handlebars Java releases, precompilation converts templates into JavaScript functions at build time, returning a Template object whose toString() yields the executable source. For a small application migration, the goal is to retain these precompiled templates in an in-memory cache to eliminate runtime parse overhead. The library does not impose an explicit limit on the number of cached templates or provide a built-in eviction policy, so memory usage is bounded only by the available heap.
Because the generated output contains executable JavaScript, loading templates from an untrusted location carries the same security weight as eval-style code. Additionally, precompiled partials cannot be dynamically resolved from the filesystem after compilation, and source changes require redeployment unless a separate reload mechanism is introduced.
In container or serverless environments with constrained heap, the unresolved decision is how to bound cache size and enforce permission boundaries for stored artifacts. Without a configurable threshold, startup time and memory consumption scale directly with template count.
What heap-based limit should determine the maximum number of cached precompiled templates, and how should access controls restrict the storage location to trusted build outputs? Is there a documented configuration pattern for capping cache size when the library itself offers no native limit?