Mark-12345 | 9 Feb 23:47
Picon

Dynamic Templates


I thought I would share the following code with the Apache Velocity
community.

Problem Description:  I wanted to use Dynamic Templates though I found the
following had massive performance implications.

-- Velocity Call Snippet --
String template = "message.to:  ${message.to} ";
StringWriter velocityWriter = new StringWriter();
velocityEngine.evaluate( velocityContext, velocityWriter, "LOG", template );
return velocityWriter.toString();
-- Velocity Call Snippet --

As such, I needed an alternate solution and guessed that if I could cache
the Velocity templates used I could see big performance gains.

I initially looked to the
org.apache.velocity.runtime.resource.loader.StringResourceLoader class to
solve my problems.   The StringResourceLoader class requires an instance of
the StringResourceRepository class, and the only implementation of
StringResourceRepository is StringResourceRepositoryImpl.  Unfortunately,
since the number of unique templates will grow over time, in time the
StringResourceRepositoryImpl.resources Map will cause an out of memory
error.

Why doesn't StringResourceRepositoryImpl use a cache with a maximum size? 
Is a cache even needed as the Velocity ResourceCacheImpl will cache
Templates?

(Continue reading)

Nathan Bubna | 10 Feb 00:01
Picon

Re: Dynamic Templates

Would you consider submitting this via
https://issues.apache.org/jira/browse/VELOCITY?

That would allow us to possibly incorporate improvements from your
code into future versions.

On Thu, Feb 9, 2012 at 2:47 PM, Mark-12345
<marks1900-post01 <at> yahoo.com.au> wrote:
>
> I thought I would share the following code with the Apache Velocity
> community.
>
>
> Problem Description:  I wanted to use Dynamic Templates though I found the
> following had massive performance implications.
>
> -- Velocity Call Snippet --
> String template = "message.to:  ${message.to} ";
> StringWriter velocityWriter = new StringWriter();
> velocityEngine.evaluate( velocityContext, velocityWriter, "LOG", template );
> return velocityWriter.toString();
> -- Velocity Call Snippet --
>
>
> As such, I needed an alternate solution and guessed that if I could cache
> the Velocity templates used I could see big performance gains.
>
> I initially looked to the
> org.apache.velocity.runtime.resource.loader.StringResourceLoader class to
> solve my problems.   The StringResourceLoader class requires an instance of
(Continue reading)

Mark-12345 | 10 Feb 06:53
Picon

Re: Dynamic Templates


More than happy to create an improvement request.  See below:

https://issues.apache.org/jira/browse/VELOCITY-817

Would you consider submitting this via
https://issues.apache.org/jira/browse/VELOCITY?

That would allow us to possibly incorporate improvements from your
code into future versions.

On Thu, Feb 9, 2012 at 2:47 PM, Mark-12345
<marks1900-post01 <at> yahoo.com.au> wrote:
>
> I thought I would share the following code with the Apache Velocity
> community.
>
>
> Problem Description:  I wanted to use Dynamic Templates though I found the
> following had massive performance implications.

--

-- 
View this message in context: http://old.nabble.com/Dynamic-Templates-tp33297076p33298309.html
Sent from the Velocity - User mailing list archive at Nabble.com.

Gmane