org.thymeleaf.util
Class CacheMap<K,V>
Object
org.thymeleaf.util.CacheMap<K,V>
- Type Parameters:
K
- The type of the cache map keysV
- The type of the cache map values
- All Implemented Interfaces:
- Serializable
public final class CacheMap<K,V>
- extends Object
- implements Serializable
Generic cache map implementation.
Features:
- A specific logger is maintained for these maps: org.thymeleaf.TemplateEngine.CACHE
- These maps apply an LRU policy and allow setting a maxSize
parameter, in which case the oldest non-used entry will be removed from
cache if maximum size is reached. Setting maxSize to -1
is equivalent to not setting it at all (no limit will be established).
- Can be set to use
SoftReference
s in order to make the cache
memory-sensitive. If this parameter is set to true, the Garbage Collector will
be able to remove entries from the cache if it is needed, before raising
an out-of-memory error (although this depends on the specific VM implementation).
- These maps are completely thread-safe. A read-write lock is used that
allows concurrent read operations but prevents write operations to be executed
concurrently with any other read or write operation.
- An
CacheMap.ICacheMapEntryValidityChecker
object can be specified when building a cache map
(and also when executing specific get operations) in order to ensure that the returned
entry/ies not only exist at the cache, but also can be considered valid according
to the criteria defined in these checker implementations.
- These maps do not create any threads, so their use is perfectly safe in
thread-sensitive scenarios like EJB containers or some cloud PaaS environments.
- If the cache logger is set to trace, a cache report
will be output every 5 minutes explaining the status of every existing cache map. Due
to the fact of no separate threads being created for reporting, this report will only
checked to be produced when any get or set operations are executed
against the cache map, so this 5-minute period can be longer if no operations are
executed.
- Since:
- 1.1.3
- Author:
- Daniel Fernández, Guven Demir
- See Also:
- Serialized Form
Constructor Summary |
CacheMap(String name,
boolean useSoftReferences,
int initialCapacity)
|
CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
CacheMap.ICacheMapEntryValidityChecker<? super K,? super V> entryValidityChecker)
|
CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
float loadFactor)
|
CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
float loadFactor,
CacheMap.ICacheMapEntryValidityChecker<? super K,? super V> entryValidityChecker)
|
CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
float loadFactor,
int maxSize)
|
CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
float loadFactor,
int maxSize,
CacheMap.ICacheMapEntryValidityChecker<? super K,? super V> entryValidityChecker)
|
CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
int maxSize)
|
CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
int maxSize,
CacheMap.ICacheMapEntryValidityChecker<? super K,? super V> entryValidityChecker)
|
Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CACHE_LOGGER_NAME
public static final String CACHE_LOGGER_NAME
logger
protected static final org.slf4j.Logger logger
CacheMap
public CacheMap(String name,
boolean useSoftReferences,
int initialCapacity)
CacheMap
public CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
CacheMap.ICacheMapEntryValidityChecker<? super K,? super V> entryValidityChecker)
CacheMap
public CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
int maxSize)
CacheMap
public CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
int maxSize,
CacheMap.ICacheMapEntryValidityChecker<? super K,? super V> entryValidityChecker)
CacheMap
public CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
float loadFactor)
CacheMap
public CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
float loadFactor,
CacheMap.ICacheMapEntryValidityChecker<? super K,? super V> entryValidityChecker)
CacheMap
public CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
float loadFactor,
int maxSize)
CacheMap
public CacheMap(String name,
boolean useSoftReferences,
int initialCapacity,
float loadFactor,
int maxSize,
CacheMap.ICacheMapEntryValidityChecker<? super K,? super V> entryValidityChecker)
put
public V put(K key,
V value)
get
public V get(K key)
get
public V get(K key,
CacheMap.ICacheMapEntryValidityChecker<? super K,? super V> validityChecker)
clear
public void clear()
clearKey
public void clearKey(K key)
getName
public String getName()
hasMaxSize
public boolean hasMaxSize()
getMaxSize
public int getMaxSize()
getUseSoftReferences
public boolean getUseSoftReferences()
size
public int size()
Copyright © 2012 The THYMELEAF team. All Rights Reserved.