velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bensman, Jeff [EESUS Non J&J]" <>
Subject RE: Template cache _kinda_ works?
Date Mon, 07 May 2007 21:33:41 GMT

Thank you for taking the time to put together the sample project.  I've run
that in my environment, and as you say, it runs as expected!  

Per your initial questions, I have not changed the max size of the cache. 

I am running in a web app, but I'm confident it's not a caching issue on the
browser.  I'm stepping through the source code, including velocity source
code, in the Eclipse debugger on Tomcat 5.5.

After an edit to my template, the Modified Date shown in Windows Explorer is
updating.  If I set a breakpoint in the isSourceModified() method of
Velocity's FileResourceLoader, it properly returns true after an edit to the
template.  And then at another breakpoint in the merge() method of Template,
I look at a toString() on the "data" property of the Template class, and it
shows the new, edited template content.  But within that merge() method, the
line that reads:
    ( (SimpleNode) data ).render( ica, writer);
seems to result in a writer that holds an old version of the template,
ignoring the new stuff in the "data" property of the Template.

I get a little lost trying to step through that render() method.  Can you
recommend any key things I could look at that might reveal what's happening?

On a different note, here are the differences I noticed between your
VelocityWebTest test project and my project...

1) your template is inside the file system of your web app, mine is not
2) you're using the version of the velocity JAR with dependencies, my app
has the dependencies separate from the velocity jar
3) when I set the velocity properties before init() I specify a
"velocimacro.library" (which works fine)

But for all 3 cases I modified my app to be configured/run like yours, and
it made no difference.

I've had a co-worker look over my shoulder to make sure I'm not doing
something insanely stupid, but if I am, he's not seeing it either.

The only thing I can think of, that I've not had the time to fully explore
yet, is that one of dependency jar files in my application is at fault.
Perhaps I'm on a wrong version of one of the dependencies and it's getting
picked up, even when using the full velocity-dep-1.5.jar jar.  (I have a
dependency on commons-collections, even outside of the use of Velocity).
This page:
lists the dependencies but doesn't give version numbers.  Are version
numbers listed somewhere that I'm missing?

Thanks for your help.


-----Original Message-----
From: Will Glass-Husain []
Sent: Sunday, May 06, 2007 11:01 AM
To: Velocity Users List
Subject: Re: Template cache _kinda_ works?

[my original note got rejected as spam.  removing the attachment, seeing if
that helps]

---------- Forwarded message ----------
From: Will Glass-Husain <>
Date: May 6, 2007 7:56 AM
Subject: Re: Template cache _kinda_ works?
To: Velocity Users List <>, "Bensman, Jeff [EESUS
Non J&J]" <>

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


On 5/4/07, Bensman, Jeff [EESUS Non J&J] <> 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

Forio Business Simulations

Will Glass-Husain

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