[my original note got rejected as spam. removing the attachment, seeing if
that helps]
---------- Forwarded message ----------
From: Will Glass-Husain <[EMAIL PROTECTED]>
Date: May 6, 2007 7:56 AM
Subject: Re: Template cache _kinda_ works?
To: Velocity Users List <[email protected]>, "Bensman, Jeff [EESUS
Non J&J]" <[EMAIL PROTECTED]>
Hi Jeff,
I built a small test servlet to check this and had no problems. I used the
StringWriter just as you described. I displayed a file, changed it, and
refreshed the page. When I refreshed in less than 10 seconds it showed the
old text. When I refreshed after 10 seconds, it showed the new text.
How are you changing the file? Obviously, the file timestamp has to change
for Velocity to notice it is new.
Also - is this a web app? Are you sure it's just not something silly like a
browser cache of the page?
(Test code attached, though it'll probably get stripped by the list serv).
WILL
On 5/4/07, Bensman, Jeff [EESUS Non J&J] < [EMAIL PROTECTED]> wrote:
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
--
Forio Business Simulations
Will Glass-Husain
[EMAIL PROTECTED]
www.forio.com
--
Forio Business Simulations
Will Glass-Husain
[EMAIL PROTECTED]
www.forio.com