velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bensman, Jeff [EESUS Non J&J]" <JBens...@EESUS.JNJ.com>
Subject Template cache _kinda_ works?
Date Fri, 04 May 2007 18:36:27 GMT
I've got the Velocity 1.5 engine integrated into my application's code and
everything seemed to be going great.  But then, I noticed that template
caching is only _kinda_ working.  

I've stepped through the Velocity source code to verify that my template
object is correctly reloading when modified (I'm using FileResourceLoader).
By verify, I mean that I can see that the ResourceLoader's isCachingOn() is
correctly returning true and the class's modificationCheckInterval reflects
my property setting (10 seconds).  And if I...

- call Velocity.getTemplate(String name) 
- run a merge( Context context, Writer writer) on the returned template 
- go out to the file system and edit the template file (after waiting 10
seconds) 
- and then re-run the Velocity.getTemplate() 

...I see that the Template object I get from getTemplate() the second time,
reflects the file system change I made (Yeah!), because its data property is
holding my new stuff.  BUT, when I call merge on it, the StringWriter I get
back reflects the old state of the template, before my change!

Here's my code: 

public static String buildView(String templateName, Map templateData )
throws Exception { 
    VelocityContext velocityContext = new VelocityContext(templateData); 
    Template velocityTemplate = Velocity.getTemplate(templateName); 
    StringWriter stringWriter = new StringWriter(); 
    velocityTemplate.merge( velocityContext, stringWriter ); 
    return stringWriter.toString(); 
} 

What am I missing?  I went back to Velocity 1.4 to make sure it wasn't some
new bug in 1.5, but 1.4 behaves the same way.

Thanks for any help, 

Jeff 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message