Uploaded image for project: 'MyFaces Tomahawk'
  1. MyFaces Tomahawk
  2. TOMAHAWK-1319

DefaultTemplateEncoder does not cache FreeMarker templates

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.1.7-SNAPSHOT
    • 1.1.7
    • Template Renderer
    • 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);
      ...

      Attachments

        Activity

          People

            lu4242 Leonardo Uribe
            paulr1984 Paul Rivera
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: