简体   繁体   English

缓存FreeMarker模板

[英]cache FreeMarker templates

I'm using the Spring class FreeMarkerConfigurationFactoryBean to retrieve FreeMarker templates. 我正在使用Spring类FreeMarkerConfigurationFactoryBean检索FreeMarker模板。 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, ie with FreeMarkerConfigurationFactoryBean? 相比之下,Spring模块提供了一个CachingTemplateResolver ,它确实提供了模板缓存,但是不使用Spring模块即使用FreeMarkerConfigurationFactoryBean就能实现吗?

Cheers, Don 干杯,唐

From the Freemarker manual , it seems caching is on by default. Freemarker手册来看,默认情况下似乎已启用缓存。

Template caching 模板缓存

FreeMarker caches templates (assuming you use the Configuration [which the Spring MBean does...] methods to create Template objects). FreeMarker缓存模板(假设您使用Configuration [Spring MBean会使用...]方法创建模板对象)。 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. 这意味着,当您调用getTemplate时,FreeMarker不仅返回生成的Template对象,而且将其存储在缓存中,因此,当下次您使用相同(或等效)路径调用getTemplate时,它将仅返回缓存的Template实例,并且将无法加载并再次解析模板文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM