Package org.webharvest
Class ThreadLocalCache<K,V>
- java.lang.Object
-
- org.webharvest.ThreadLocalCache<K,V>
-
- All Implemented Interfaces:
Cache<K,V>
public final class ThreadLocalCache<K,V> extends Object implements Cache<K,V>
Cache
implementation based onThreadLocal
, that is, allowing each thread to have separate cache bindings. It is especially useful for caching non thread-safe objects. Since it is possible, that the application will need to use differentThreadLocalCache
instances, for example one cache for script engines and another cache for database connections, we do not enforce this class to be singleton. However, it is mandatory to have only one instance ofThreadLocalCache
per cache usage context (e.g. single instance for caching script engines and another, single instance for caching database connections) - usually, it is a job of IoC container.- Since:
- 2.1.0-SNAPSHOT
- Version:
- %I%, %G%
- Author:
- Piotr Dyraga
- See Also:
Cache
-
-
Constructor Summary
Constructors Constructor Description ThreadLocalCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(K key)
Returns {@link true} ifCache
contains object identified by the given key.void
invalidate(K key)
Discard value cached under the specified key.V
lookup(K key)
Returns value associated with the specified key.void
put(K key, V value)
Associates the specified value with the specified key inCache
.
-
-
-
Method Detail
-
contains
public boolean contains(K key)
Returns {@link true} ifCache
contains object identified by the given key.
-
lookup
public V lookup(K key)
Returns value associated with the specified key. If for the given key, no value is currently cached, then {@link null} is returned.
-
invalidate
public void invalidate(K key)
Discard value cached under the specified key.- Specified by:
invalidate
in interfaceCache<K,V>
- Parameters:
key
- key of the cache binding which is going to be invalidated.
-
-