views:

392

answers:

1

Hi,

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

+4  A: 

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.

Chris Kimpton