Package org.ametys.core.util
Class CachingComponent<K,V>
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.util.CachingComponent<K,V>
-
- Type Parameters:
K
- the type of keys for caching objects by this component.V
- the type of objects cached by this component.
- All Implemented Interfaces:
LogEnabled
,Disposable
,Initializable
public class CachingComponent<K,V> extends AbstractLogEnabled implements Initializable, Disposable
Simple memory cache with a thread clearing the cache every day.
-
-
Constructor Summary
Constructors Constructor Description CachingComponent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addObjectInCache(K key, V object)
Adds a key/object pair in the cache.protected void
clearCache()
Removes all entries from the cache.void
dispose()
protected V
getObjectFromCache(K key)
Returns an object from the cache, correspondong to the specified key, or null if none.void
initialize()
protected boolean
isCacheEnabled()
Returns true if the cache is enabled.protected void
removeObjectFromCache(K key)
Removes a key/object pair in the cache.-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Constructor Detail
-
CachingComponent
public CachingComponent()
-
-
Method Detail
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
getObjectFromCache
protected V getObjectFromCache(K key)
Returns an object from the cache, correspondong to the specified key, or null if none.- Parameters:
key
- the object's key.- Returns:
- the object from cache.
-
addObjectInCache
protected void addObjectInCache(K key, V object)
Adds a key/object pair in the cache.- Parameters:
key
- the object's key.object
- the object to be cached.
-
removeObjectFromCache
protected void removeObjectFromCache(K key)
Removes a key/object pair in the cache.- Parameters:
key
- the object's key.
-
clearCache
protected void clearCache()
Removes all entries from the cache.
-
isCacheEnabled
protected boolean isCacheEnabled()
Returns true if the cache is enabled.- Returns:
- true if the cache is enabled.
-
-