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
Simple memory cache with a thread clearing the cache every day.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addObjectInCache
(K key, V object) Adds a key/object pair in the cache.protected void
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
protected boolean
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 Details
-
CachingComponent
public CachingComponent()
-
-
Method Details
-
initialize
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
dispose
- Specified by:
dispose
in interfaceDisposable
-
getObjectFromCache
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
Adds a key/object pair in the cache.- Parameters:
key
- the object's key.object
- the object to be cached.
-
removeObjectFromCache
Removes a key/object pair in the cache.- Parameters:
key
- the object's key.
-
clearCache
Removes all entries from the cache. -
isCacheEnabled
Returns true if the cache is enabled.- Returns:
- true if the cache is enabled.
-