Interface ICacheManager
-
- All Known Implementing Classes:
AbstractCacheManager
,StandardCacheManager
public interface ICacheManager
Common interface for all cache manager implementations.
This class is in charge of providing the corresponding cache objects to the template engine. Every call to each of the
getXCache()
methods must always return the XCache object (i.e. only one cache object should be ever created for each type of cache, and returned every time it is requested).These caches are predefined:
- A template cache, used for storing parsed templates referenced
by their template name and other resolution info (see
TemplateCacheKey
). - An expression cache, used for storing expression evaluation artifacts
(for example,
Expression
parsed trees, OGNL/Spring EL parsed trees, etc). Given that this cache can usually store objects of different classes (referenced by their String representation), prefixes are normally applied to the String keys in order to being able to differentiate these classes when retrieving cache entries.
Only the caches listed above are needed by the template engine when the standard dialects are being used, but users might want to define new dialects and use new types of caches, which can be provided by the cache manager using the
getSpecificCache(String)
method.Any of these methods could return null, in which case the engine will consider that no cache must be applied for that specific function.
Note a class with this name existed since 2.0.0, but it was completely reimplemented in Thymeleaf 3.0
- Since:
- 3.0.0
- Author:
- Daniel Fernández
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clearAllCaches()
Clears all the caches managed by this cache manager instance.List<String>
getAllSpecificCacheNames()
Returns a list with the names of all the specific caches managed by this implementation.ICache<ExpressionCacheKey,Object>
getExpressionCache()
Returns the cache of expression evaluation artifacts.<K,V>
ICache<K,V>getSpecificCache(String name)
Returns a specific (non-default) cache, by its name.ICache<TemplateCacheKey,TemplateModel>
getTemplateCache()
Returns the cache of parsed templates.
-
-
-
Method Detail
-
getTemplateCache
ICache<TemplateCacheKey,TemplateModel> getTemplateCache()
Returns the cache of parsed templates. Keys are the template names, as specified at the
TemplateEngine.process(String, org.thymeleaf.context.IContext)
method.- Returns:
- the cache of parsed templates.
-
getExpressionCache
ICache<ExpressionCacheKey,Object> getExpressionCache()
Returns the cache of expression evaluation artifacts.
This cache is meant to store artifacts of diverse nature needed along the process of parsing and executing expressions in the several languages available: Standard expressions, OGNL expressions, Spring EL expressions...
Parsing these expressions usually results in some kind of syntax tree object that represents the expression, and this is what this cache usually stores.
Keys are the expressions themselves (their String representation), along with a type that is normally used for identifying the nature of the object being cached (for example
{"ognl","person.name"}
).- Returns:
- the cache of expression artifacts
-
getSpecificCache
<K,V> ICache<K,V> getSpecificCache(String name)
Returns a specific (non-default) cache, by its name.
User-defined dialects might make use of additional caches (besides template, and expression) defined at custom-made implementations of this interface, and they should use this method to retrieve them by their name.
Note the default
StandardCacheManager
will returnnull
for every call to this method, as it should be custom implementations of this interface (or extensions ofAbstractCacheManager
or extensionsStandardCacheManager
) who implement these specific caches and offer their names through thegetAllSpecificCacheNames()
method.- Type Parameters:
K
- the type of the cache keysV
- the type of the cache values- Parameters:
name
- the name of the needed cache- Returns:
- the required cache
-
getAllSpecificCacheNames
List<String> getAllSpecificCacheNames()
Returns a list with the names of all the specific caches managed by this implementation.
Might return null if no specific caches are managed.
Note the default
StandardCacheManager
will returnnull
, as it should be custom implementations of this interface (or extensions ofAbstractCacheManager
or extensionsStandardCacheManager
) who implement these specific caches and offer their names through thegetAllSpecificCacheNames()
method.- Returns:
- a list with all the names of the "specific caches"
- Since:
- 2.0.16
-
clearAllCaches
void clearAllCaches()
Clears all the caches managed by this cache manager instance.
This method is mainly intended for use from external tools that might need to clean all caches completely, without having to worry about implementation details.
- Since:
- 2.0.16
-
-