Re: templates path not reloading on clearTemplateCache()

Matthew Anderson <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Just a little follow up on this.

Is setDirectoryForTemplateLoading  thread safe? Documentation doesnt say if
it is or not.

setTemplateLoader is not thread safe

clearTemplateCache() is thread safe

thanks,
matthew

On Tue, Feb 10, 2009 at 5:34 AM, Attila Szegedi <[email protected]> wrote:

> Hm... This is strange - FreeMarker's FileTemplateLoader doesn't use
> canonicalized paths to load templates...
>
> Now, instead of clearing the template cache, you could call
> Configuration.setDirectoryForTemplateLoading() again with the path (or
> Configuration.setTemplateLoader() with a recreated
> FileTemplateLoader). That will recreate the FileTemplateLoader object
> and should get rid of any stuck state (with the disclaimer that there
> should be no such stuck state anyway). Changing the template loader
> also internally triggers cache clearing.
>
> There is actually another reason why would you want to recreate the
> template loader if you're chaning symlinks. The reason is that a
> FileTemplateLoader will resolve a path to a canonical path on
> construction, and will refuse to serve files from outside the
> canonical location the symlink resolves to. Note: it is _not_ using
> the canonical path to look up templates, it is just comparing the
> canonical path of the root template directory with the canonical path
> of the template, and if the former isn't a prefix of the latter,
> refuses to load the template.
>
> Alternatively, you can just create a FileTemplateLoader with the two-
> arg constructor and pass true for parameter "allowLinking" in the
> constructor, and then it won't care about canonical paths at all.
>
> Attila.
>
> On 2009.02.07., at 20:53, Matthew Anderson wrote:
>
> > We are having an issue that when we clear the template cache using
> > clearTemplateCache(), we dont get the new templates.  Here is our
> > settup.
> >
> > We have a symlinked path to our templates.
> >
> > path to templates that we load: /mypath/templates
> > This path is a symlink pointing to the real hard linked path for the
> > templates
> > ie: v1 of templates path is /local/templates/v1
> > v2 of templates path os /local/templates/v2
> >
> > Reproduce steps:
> > /mypath/templates points to /local/templates/v1
> > We deploy new templates to v2 path, and flip the symlink /mypath/
> > templates to now point to /local/templates/v2
> >
> > Every five minutes, our service checks to see if the canonical path
> > has changed for the template dir path, and if it has,  then we call
> > clearTemplateCache()
> >
> > However, the templates from v1 path are still getting picked up. Is
> > there a way to force freemarker to reload the symlink path?  It
> > seems as if there is a handle somewhere to the old symlinked
> > directory.
> >
> > thanks,
> > matthew
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with
> Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code
> to
> build responsive, highly engaging applications that combine the power of
> local
> resources and data with the reach of the web. Download the Adobe AIR SDK
> and
> Ajax docs to start building applications today-
> http://p.sf.net/sfu/adobe-com
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.