DefaultTemplateEncoder does not cache FreeMarker templates
----------------------------------------------------------

                 Key: TOMAHAWK-1319
                 URL: https://issues.apache.org/jira/browse/TOMAHAWK-1319
             Project: MyFaces Tomahawk
          Issue Type: Bug
          Components: Template Renderer
    Affects Versions: 1.1.7-SNAPSHOT
         Environment: tomcat 6.0.16
java 1.6.0_05
MyFaces tomahawk-sandbox-1.1.7-SNAPSHOT
            Reporter: Paul Rivera
            Priority: Minor


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);
   ...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to