RE: TemplateLoader/Configuration Question
"Andy Zeneski" <[email protected]> Wed, 26 Feb 2003 10:51:09 -0500
| Newsgroups | gmane.comp.web.freemarker.devel,gmane.comp.java.jpublish.devel |
|---|---|
| Message-ID | <[email protected]> |
Anthony,
I am was looking at mine too and I need a Configuration object in order to
do <#include> properly. Without the Configuration it couldn't find the
included files.
Now, does JPublish create a unique instance of the ViewRenderer for each
webapp? If so, can we not create the FTL Configuration in the init() method
or does init() get called before setSiteContext()?
I assumed init() was called first, so I did this in my render method:
BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
WrappingTemplateModel.setDefaultObjectWrapper(wrapper);
if (config == null) {
synchronized(this) {
if (config == null) {
config =
freemarker.template.Configuration.getDefaultConfiguration();
config.setDirectoryForTemplateLoading(siteContext.getContextRoot());
config.setObjectWrapper(wrapper);
Debug.logInfo("Set directory for template (includes)
loading: " + siteContext.getContextRoot(), module);
}
}
}
So, only the first page will have to load the configuration. BTW config is
an instance variable. This might not work if ViewRenderer instances are
shared between webapps, this I have not tested yet.
-Andy
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of
> Anthony Eden
> Sent: Wednesday, February 26, 2003 9:53 PM
> To: [email protected]
> Subject: [Freemarker-devel] TemplateLoader/Configuration Question
>
>
> Right now JPublish constructs a Template directly and thus can
> not take advantage of any caching in template engines. I am
> working on the FreeMarker view renderer right now and I have a
> question about performance:
>
> Which is likely to pose a larger performance threat (speed and memory):
>
> a.) Construct a new Configuration and TemplateLoader for every
> request. In this case the template loader will still have the
> ability to return a valid value for the getLastModified() method.
> b.) Construct a Template without caching for every request and
> thus require the template to be parsed for every request.
>
> Sincerely,
> Anthony Eden
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Scholarships for Techies!
> Can't afford IT training? All 2003 ictp students receive scholarships.
> Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
> www.ictp.com/training/sourceforge.asp
> _______________________________________________
> FreeMarker-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-devel
>
-------------------------------------------------------
This SF.net email is sponsored by: Scholarships for Techies!
Can't afford IT training? All 2003 ictp students receive scholarships.
Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
www.ictp.com/training/sourceforge.asp