public class TemplateCache
extends java.lang.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)
Creates a new template cache with a custom template loader that is used
to load the templates.
|
TemplateCache(TemplateLoader templateLoader,
CacheStorage cacheStorage)
Creates a new template cache with a custom template loader that is used
to load the templates.
|
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. |
CacheStorage |
getCacheStorage() |
long |
getDelay()
Gets the delay in milliseconds between checking for newer versions of a
template source.
|
static java.lang.String |
getFullTemplatePath(Environment env,
java.lang.String currentTemplateDir,
java.lang.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(java.lang.String name,
java.util.Locale locale,
java.lang.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(java.lang.String name,
java.util.Locale locale,
java.lang.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)
Sets the configuration object to which this cache belongs.
|
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)
templateLoader
- the template loader to use.public TemplateCache(TemplateLoader templateLoader, CacheStorage cacheStorage)
templateLoader
- the template loader to use.public void setConfiguration(Configuration config)
public TemplateLoader getTemplateLoader()
public CacheStorage getCacheStorage()
public Template getTemplate(java.lang.String name, java.util.Locale locale, java.lang.String encoding, boolean parseAsFTL) throws java.io.IOException
For the meaning of the parameters see Configuration.getTemplate(String, Locale, String, boolean)
.
null
if the template was not found.java.io.IOException
public 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(java.lang.String name, java.util.Locale locale, java.lang.String encoding, boolean parse) throws java.io.IOException
setDelay(long)
alone does.
For the meaning of the parameters, see
getTemplate(String, Locale, String, boolean)
.java.io.IOException
public static java.lang.String getFullTemplatePath(Environment env, java.lang.String currentTemplateDir, java.lang.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 currentDir
currentTemplateDir
- must end with "/", might contains "://".