velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
Subject Re: template caching
Date Mon, 26 Nov 2001 04:00:12 GMT
On 11/25/01 5:12 AM, "Thomas Ã…hlen" <> wrote:

> I have just been browsing throu the source trying to understand the Cache
> implementation.
> Guess one needs more than 30 minutes to exactly understand what is
> happening. ;)
> I just wanted to check one thing.
> Since I store my templates in a database and have implementet an object
> cache myself so I don't have any need for Velocitys cache. But then I
> realised that you might cache the NodeTree so that a template only need to
> be parsed one time. So that when I call evaluate next time with the same
> template the only thing velocity should need to to is create an
> InternalContextAdapterImpl and call nodeTree.render( ica, writer ); and thus
> saving an rather expensive parse. I suppose that the nodeTree isn't
> destoryed by the rendering of the template?


> But looking through the code I can't find that you cache the NodeTree
> produced by the parsing of the template or have I missed something? I guess
> there can be a big performance improvment if it is cached.

Believe it or not, we did think of that :)  The ResourceManager takes care
of that (and in 1.3, the cache is pluggable...)
> Since I call velocitys evaluate with the template as a string there is no
> unique identifier so it can't be cached. The way I see it I could extend
> and use the logtag as a unique templatename and make my own
> NodeTree cache :)

If you are loading templates from a database and are using Velocity's
evaluate(), then yes, you don't get the advantage of the cache. I have
wanted to extend and to return a cacheable
Template that you can cache and reuse.

However, this functionality in Velocity/VelocityApp is meant for dynamic
"construct once and throw away" type of stuff.  You would be better served
by writing a resource loader (use or model after the current

> Is there any sence in what I am thinking or have I missunderstood something?
> Thomas
> Comment: I can't find that this attribute is used anywhere in Velocity?

No, and it should be out of the 1.3 tree...I mean to nip that out at the RI
refactoring...  It's now gone... Thx.

> []
>   /**
>    * The caching system used by the Velocity Runtime
>    */
>   private  Hashtable globalCache;
>   /**
>    * Initialize the global cache use by the Velocity
>    * runtime. Cached templates will be stored here,
>    * as well as cached content pulled in by the #include
>    * directive. Who knows what else we'll find to
>    * cache.
>    */
>   private void initializeGlobalCache()
>   {
>       globalCache = new Hashtable();
>   }
> --
> To unsubscribe, e-mail:
> <>
> For additional commands, e-mail:
> <>

Geir Magnusson Jr.                           
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message