Dónal
Dónal

Reputation: 187539

cache FreeMarker templates

I'm using the Spring class FreeMarkerConfigurationFactoryBean to retrieve FreeMarker templates. I would like these templates to be cached, but there doesn't appear to be any way to indicate that this behaviour is required.

In contrast, Spring modules provides a CachingTemplateResolver which does provide template caching, but is it possible to achieve this without using Spring modules, i.e. with FreeMarkerConfigurationFactoryBean?

Cheers, Don

Upvotes: 2

Views: 4110

Answers (1)

Chris Kimpton
Chris Kimpton

Reputation: 5541

From the Freemarker manual, it seems caching is on by default.

Template caching

FreeMarker caches templates (assuming you use the Configuration [which the Spring MBean does...] methods to create Template objects). This means that when you call getTemplate, FreeMarker not only returns the resulting Template object, but stores it in a cache, so when next time you call getTemplate with the same (or equivalent) path, it just returns the cached Template instance, and will not load and parse the template file again.

Upvotes: 6

Related Questions