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 RE: Template cache _kinda_ works?
Date Tue, 08 May 2007 15:04:26 GMT
Okay.  Problem solved.  As anticipated, it was a relatively simple
issue I was missing.

There was another difference between Will's VelocityWebTest test
project and my project that I initially overlooked.  My template was
making a call to a macro defined in the template.  And it was in this
macro that I was continually making my edits and expecting them to be
seen. I thought macros in a template would be re-parsed every time.  
Turns out that even when you set...
   file.resource.loader.cache=false
   velocimacro.library.autoreload=true
...macros defined in the template are not re-parsed.

I discovered that all I had to do was set...
   velocimacro.permissions.allow.inline.to.replace.global=true

With this setting I can leave caching on, autoreload off, _and_ my
edits to template defined macros are being seen.  Perfect!

Thanks to everyone that offered ideas,

Jeff


BTW, my exploration of the version numbers of dependent jars, seems to
indicate that, for my purposes anyway, commons-collections 3.2 and
commons-lang 2.3 work just as well as the documented requirements
of commons-collections 3.1 and commons-lang 2.1.


-----Original Message-----
From: Will Glass-Husain [mailto:wglasshusain@gmail.com]
Sent: Monday, May 07, 2007 6:23 PM
To: Velocity Users List
Subject: Re: Template cache _kinda_ works?


maybe you have multiple copies of the jar file as you suggest?

I've had problems before (with other libraries) with things working when at
a break point but not while running continuously.  it turned out that one
classpath was active at the break and a different one while running.

be interesting to do a print/log statement while running to see if you have
the same results (rather than breaking and manually checking).

Full dependency version info at:
http://velocity.apache.org/engine/releases/velocity-1.5/build.html

WILL

On 5/7/07, Bensman, Jeff [EESUS Non J&J] <JBensma1@eesus.jnj.com> wrote:
>
> Will,
>
> 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:
> http://velocity.apache.org/engine/devel/jar-dependencies.html
> lists the dependencies but doesn't give version numbers.  Are version
> numbers listed somewhere that I'm missing?
>
> Thanks for your help.
>
> Jeff
>
>
>
> -----Original Message-----
> From: Will Glass-Husain [mailto:wglasshusain@gmail.com]
> 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 <wglasshusain@gmail.com>
> Date: May 6, 2007 7:56 AM
> Subject: Re: Template cache _kinda_ works?
> To: Velocity Users List <user@velocity.apache.org>, "Bensman, Jeff [EESUS
> Non J&J]" <JBensma1@eesus.jnj.com>
>
> 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] < JBensma1@eesus.jnj.com> 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
> wglass@forio.com
> www.forio.com
>
>
>
> --
> Forio Business Simulations
>
> Will Glass-Husain
> wglass@forio.com
> www.forio.com
>



-- 
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com

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