Hello Sandep,

for some of my representations I use FreeMarker as the template
engine. FreeMarker does automatic caching of the templates, probably
Velocity has a similar feature. In any way, what I do is to use a
single(ton) FreeMarkerUtils class that is the one loading the
templates, and the resources ask that class for the templates. The
templates are classpath resources. You can check its code here:

http://trac.calenco.com/browser/branches/stable/src/com/calenco/utils/FreeMarkerUtil.java

and a resource using it here:

http://trac.calenco.com/browser/branches/stable/src/com/calenco/resource/system/WorkspacesResource.java

(check the toHTML() method)

Hope this helps. Good luck.


On Fri, Mar 18, 2011 at 10:43 PM, sandeep <sanfin...@gmail.com> wrote:
> Hi,
>
> I am currently using TemplateRepresentation to handle the feed creation.
>
> templateRepr = new 
> TemplateRepresentation(this.getVelocityTemplateRepr(),params, 
> MediaType.APPLICATION_ATOM_XML);
>
> During debugging realized that the template File (*.vm) is being opened for 
> every get request. Is there a way to somehow cache the velocity template ?
>
> One way I could think of is to create a TemplateRepresentation without the 
> Map<string,obj> params and populate the updated params in every get request 
> and set available flag to true.?
>
> Is there a thread safe way to do the same?
>
> Thanks & Regards,
> Sandeep
>
> new TemplateRepresentation(this.getVelocityTemplateRepr(),
> , MediaType.APPLICATION_ATOM_XML)
>
> //in every get...
> tempRepresentation.setDataModel(..)
> tempRepresentation.setAvailable(true)
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2712483
>



-- 
Fabián Mandelbaum
IS Engineer

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2712587

Reply via email to