Anand Varkey Philips
Anand Varkey Philips

Reputation: 2075

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

From the 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.

Can anyone help? I am using spring boot.

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

Upvotes: 1

Views: 1445

Answers (1)

ddekany
ddekany

Reputation: 31152

Just set the template_update_delay setting to something absurdly high (without hitting the long ms limit). Not sure how you configure FreeMarker, but if in application.properties then like this:

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

Note that cache size limits still apply, so old entries may be removed if you reach that.

BTW, you can find all the things you can write after spring.freemarker.settings. here: https://freemarker.apache.org/docs/api/freemarker/template/Configuration.html#setSetting-java.lang.String-java.lang.String-

Upvotes: 2

Related Questions