我们如何将模板缓存设置为从不在 apache 免费标记中重新加载?

How can we set template cache to never reload in apache free marker?

来自documentation

If you change the template file, then FreeMarker will re-load and re-parse the template automatically when you get the template next time. However, since always checking for changes can be burden for a system that processes lot of templates, there is a Configuration level setting called "update delay" (defaults is 5 seconds). Until this much time has elapsed since the last checking for a newer version, FreeMarker will not check again if the template was changed. If you want to see the changes without delay, set this setting to 0. Note that some template loaders won't see that a template was changed because of the underlying storage mechanism doesn't support that; for example, class-loader based template loaders may have this problem.

有人能帮忙吗?我正在使用 spring 启动。

String jsonMessage = processTemplateIntoString(configuration.getTemplate("customjsontemplate.ftl"), dataMap);

只需将 template_update_delay 设置设置得高得离谱(没有达到 long 毫秒限制)。不确定您如何配置 FreeMarker,但如果在 application.properties 中,则像这样:

# Never re-validate cached entries:
spring.freemarker.settings.template_update_delay=100000000 h

请注意,缓存大小限制仍然适用,因此如果达到该限制,旧条目可能会被删除。

顺便说一句,您可以在 spring.freemarker.settings. 之后找到所有可以写的东西:https://freemarker.apache.org/docs/api/freemarker/template/Configuration.html#setSetting-java.lang.String-java.lang.String-