public class TemplateCache extends Object
TemplateLoader that you can specify in the constructor.
Some aspects of caching is delegated to a CacheStorage that you can also specify in the constructor.
Typically you don't instantiate or otherwise use this class directly. The Configuration embeds an
instance of this class, that you access indirectly through Configuration.getTemplate(String) and other
Configuration API-s. Then TemplateLoader and CacheStorage can be set with
Configuration.setTemplateLoader(TemplateLoader) and
Configuration.setCacheStorage(CacheStorage).
| Constructor and Description |
|---|
TemplateCache()
Deprecated.
Use
TemplateCache(TemplateLoader) instead. The default loader is useless in most
applications, also it can mean a security risk. |
TemplateCache(TemplateLoader templateLoader)
Deprecated.
|
TemplateCache(TemplateLoader templateLoader,
CacheStorage cacheStorage)
Deprecated.
|
TemplateCache(TemplateLoader templateLoader,
CacheStorage cacheStorage,
Configuration config) |
TemplateCache(TemplateLoader defaultTemplateLoader,
Configuration config)
Creates an instance with the default
CacheStorage. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all entries from the cache, forcing reloading of templates
on subsequent
getTemplate(String, Locale, String, boolean)
calls. |
protected static TemplateLoader |
createLegacyDefaultTemplateLoader()
Creates the default
TemplateLoader used in 2.3.0-compatible mode. |
CacheStorage |
getCacheStorage() |
long |
getDelay()
Gets the delay in milliseconds between checking for newer versions of a
template source.
|
static String |
getFullTemplatePath(Environment env,
String currentTemplateDir,
String targetTemplatePath)
Resolves a path-like reference to a template (like the one used in
#include or #import), assuming
a current directory. |
boolean |
getLocalizedLookup()
Returns if localized template lookup is enabled or not.
|
Template |
getTemplate(String name,
Locale locale,
String encoding,
boolean parseAsFTL)
Retrieves the template with the given name (and according the specified further parameters) from the
template cache, loading it into the cache first if it's missing/staled.
|
TemplateLoader |
getTemplateLoader() |
void |
removeTemplate(String name,
Locale locale,
String encoding,
boolean parse)
Removes an entry from the cache, hence forcing the re-loading of it when
it's next time requested.
|
void |
setConfiguration(Configuration config)
Deprecated.
Use the
TemplateCache(TemplateLoader, CacheStorage, Configuration) constructor. |
void |
setDelay(long delay)
Sets the delay in milliseconds between checking for newer versions of a
template sources.
|
void |
setLocalizedLookup(boolean localizedLookup)
Setis if localized template lookup is enabled or not.
|
public TemplateCache()
TemplateCache(TemplateLoader) instead. The default loader is useless in most
applications, also it can mean a security risk.user.dir), then from the classpath.public TemplateCache(TemplateLoader templateLoader)
TemplateCache(TemplateLoader, CacheStorage, Configuration) instead.public TemplateCache(TemplateLoader templateLoader, CacheStorage cacheStorage)
TemplateCache(TemplateLoader, CacheStorage, Configuration) instead.public TemplateCache(TemplateLoader defaultTemplateLoader, Configuration config)
CacheStorage.public TemplateCache(TemplateLoader templateLoader, CacheStorage cacheStorage, Configuration config)
templateLoader - The TemplateLoader to use. Can't be null.cacheStorage - The CacheStorage to use. Can't be null.config - The Configuration this cache will be used for. Can be null for backward
compatibility, as it can be set with setConfiguration(Configuration) later.protected static TemplateLoader createLegacyDefaultTemplateLoader()
TemplateLoader used in 2.3.0-compatible mode.public void setConfiguration(Configuration config)
TemplateCache(TemplateLoader, CacheStorage, Configuration) constructor.public TemplateLoader getTemplateLoader()
public CacheStorage getCacheStorage()
public Template getTemplate(String name, Locale locale, String encoding, boolean parseAsFTL) throws IOException
For the meaning of the parameters see Configuration.getTemplate(String, Locale, String, boolean).
null if the template was not found.IOExceptionpublic long getDelay()
public void setDelay(long delay)
delay - the new value of the delaypublic boolean getLocalizedLookup()
public void setLocalizedLookup(boolean localizedLookup)
public void clear()
getTemplate(String, Locale, String, boolean)
calls. If the configured template loader is
stateful, then its
StatefulTemplateLoader.resetState() method is invoked as well.public void removeTemplate(String name, Locale locale, String encoding, boolean parse) throws IOException
setDelay(long) alone does.
For the meaning of the parameters, see
getTemplate(String, Locale, String, boolean).IOExceptionpublic static String getFullTemplatePath(Environment env, String currentTemplateDir, String targetTemplatePath)
#include or #import), assuming
a current directory. This gives a full, even if non-normalized template name, that could be used for
getTemplate(String, Locale, String, boolean). This is mostly used when a template refers to another
template.targetTemplatePath - If starts with "/" or contains "://", it's an absolute path and currentDir
will be ignored, otherwise it's interpreted as relative to currentDircurrentTemplateDir - must end with "/", might contains "://".