Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.1.7-SNAPSHOT
-
None
-
tomcat 6.0.16
java 1.6.0_05
MyFaces tomahawk-sandbox-1.1.7-SNAPSHOT
Description
The DefaultTemplateEncoder used by TemplateRenderer does not cache the templates properly.
In DefaultTemplateEncoder.encodeTemplate(), it instantiates a new Configuration instance every time this method is called. FreeMarker's cache is stored in Configuration->TemplateCache->CacheStorage. If we keep creating a new instance of Configuration in DefaultTemplateEncoder.encodeTemplate(), the CacheStorage will always be empty and FreeMarker will have to parse the file again.
Here's the code:
public class DefaultTemplateEncoder implements TemplateEncoder {
private static final Log log = LogFactory.getLog(DefaultTemplateEncoder.class);
private static final String TEMPLATE_DIRECTORY = "template";
public void encodeTemplate(FacesContext context, UIComponent component, Renderer renderer, String template, Object dataModel) throws IOException {
Configuration cfg = new Configuration();
if(log.isDebugEnabled())
log.debug("Encoding template : " renderer.getClass().getResource(TEMPLATE_DIRECTORY"/"+template));
TemplateLoader templateLoader = new ClassTemplateLoader(renderer.getClass(), TEMPLATE_DIRECTORY);
...