Template Caches

An object that implements the interface freemarker.template.TemplateCache vends templates. Most users will be able to get by with the default implementation, which is freemarker.template.FileTemplateCache, which gives you the capability of loading templates either via the file system or via the classloader mechanism.

If you use the constructor that takes a File as an argument, this is assumed to be an existing directory on the file system. When you deploy your web app, it is often better to have templates loaded via the Class.getResource() mechanism. This allows all of the templates to be stored in a .jar or .war file for easy deployment. Then you would use the constructor that takes a Class and a string as an argument. The cache object attempts to load via the Class.getResource() method, prepending the name of the file with the string.

You may refer to the guestbook example for sample Java code that uses FileTemplateCache.