Re: Template Caching doesn't work
Daniel Dekany <[email protected]> Sat, 20 Apr 2013 23:12:05 +0200
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
The problem is that setting the TemplateLoader drops the cache. Also,
it's not allowed to modify the Configuration after have started using
it from multiple threads (unless you do the necessary
synchronizations).
Note that the template name can be a path like
"myemailtemplates/whatever/thistemplate.ftl". So probably you
shouldn't have a templatedir parameter at all.
--
Thanks,
Daniel Dekany
Friday, April 19, 2013, 8:59:51 PM, chintan4181 wrote:
> Hi,
>
> I am using Freemarker for email template with spring. I want to cache my
> template, but somehow it's not working. Below is my configuration
>
> Spring configuration:
> <bean id="freemarkerMailConfiguration"
> class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
> <property name="freemarkerSettings">
> <props>
> <prop
> key="cache_storage">strong:50, soft:500</prop>
> <prop
> key="template_update_delay">40</prop>
> </props>
> </property>
> </bean>
>
> private String getContent(String templateFileName, String templatedir,
> java.util.Map<String, Object> dynamicParams) throws Exception {
> if(ftl == null)
> ftl = new FileTemplateLoader(new File(templatedir));
>
> configuration.setTemplateLoader(ftl);
> //configuration object is injected
> by spring which has //MruStorage cache with 50,500
>
> template =
> configuration.getTemplate(templateFileName); //all the time
> parse same template again.
> String result =
> FreeMarkerTemplateUtils.processTemplateIntoString(template, dynamicParams);
>
> return result;
> }
>
> I am calling getContent method for 3 times before sending email. but all
> times it prints below message in the log
> Could not find template in cache, creating new one;
> id=[mail-template.txt[en_US,Cp1252,parsed] ]
> Compiling FreeMarker template mail-template.txt[en_US,Cp1252,parsed]
>
> Can somebody tell me, how do i cache the template so it retrieve from Cache.
>
> Thanks
> Chintan
>
>
>
> --
> View this message in context:
> http://freemarker.624813.n4.nabble.com/Template-Caching-doesn-t-work-tp4654527.html
> Sent from the freemarker-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
--
Thanks,
Daniel Dekany
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter