Package org.cyclos.impl.utils.cache
Class AbstractCache<K extends Serializable,V extends Serializable>
- java.lang.Object
-
- org.cyclos.impl.utils.cache.AbstractCache<K,V>
-
- All Implemented Interfaces:
Cache<K,V>
- Direct Known Subclasses:
GuavaCache
public abstract class AbstractCache<K extends Serializable,V extends Serializable> extends Object implements Cache<K,V>
Base implementation forCache
-
-
Field Summary
Fields Modifier and Type Field Description protected CacheHandlerImplementorcacheHandlerprotected static org.apache.logging.log4j.LoggerLOGprotected ConcurrentHashMap<K,org.cyclos.impl.utils.cache.AbstractCache.ProducerWrapper<K,V>>pendingProducersprotected CacheType<K,V>type
-
Constructor Summary
Constructors Constructor Description AbstractCache(CacheHandlerImplementor cacheHandler, CacheType<K,V> type)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all entries in this cacheprotected abstract booleancontains(K key)Returns whether the cache contains the given keyvoiddestroy()Destroys this cache instanceprotected abstract voiddoClear()protected abstract voiddoEvict(Collection<K> keys)protected abstract VdoGet(K key, Callable<V> producer)Must be implemented to actually return the cached value, or produce a new one if not presentvoidevict(Collection<K> keys)Evicts the given keys, if presentvoidevict(Predicate<K> predicate)Evicts the keys matching the given predicateVget(K key, Callable<V> producer)Returns the value currently associated with the given key, or gets one from the given producer if noneprotected abstract Collection<K>getKeys(Predicate<K> predicate)CacheType<K,V>getType()Returns this cache type
-
-
-
Field Detail
-
LOG
protected static final org.apache.logging.log4j.Logger LOG
-
type
protected final CacheType<K extends Serializable,V extends Serializable> type
-
cacheHandler
protected final CacheHandlerImplementor cacheHandler
-
pendingProducers
protected ConcurrentHashMap<K extends Serializable,org.cyclos.impl.utils.cache.AbstractCache.ProducerWrapper<K extends Serializable,V extends Serializable>> pendingProducers
-
-
Constructor Detail
-
AbstractCache
public AbstractCache(CacheHandlerImplementor cacheHandler, CacheType<K,V> type)
-
-
Method Detail
-
clear
public final void clear()
Description copied from interface:CacheRemoves all entries in this cache- Specified by:
clearin interfaceCache<K extends Serializable,V extends Serializable>
-
destroy
public void destroy()
Description copied from interface:CacheDestroys this cache instance- Specified by:
destroyin interfaceCache<K extends Serializable,V extends Serializable>
-
evict
public final void evict(Collection<K> keys)
Description copied from interface:CacheEvicts the given keys, if present- Specified by:
evictin interfaceCache<K extends Serializable,V extends Serializable>
-
evict
public void evict(Predicate<K> predicate)
Description copied from interface:CacheEvicts the keys matching the given predicate- Specified by:
evictin interfaceCache<K extends Serializable,V extends Serializable>
-
get
public final V get(K key, Callable<V> producer)
Description copied from interface:CacheReturns the value currently associated with the given key, or gets one from the given producer if none- Specified by:
getin interfaceCache<K extends Serializable,V extends Serializable>
-
getType
public final CacheType<K,V> getType()
Description copied from interface:CacheReturns this cache type- Specified by:
getTypein interfaceCache<K extends Serializable,V extends Serializable>
-
contains
protected abstract boolean contains(K key)
Returns whether the cache contains the given key
-
doClear
protected abstract void doClear()
-
doEvict
protected abstract void doEvict(Collection<K> keys)
-
doGet
protected abstract V doGet(K key, Callable<V> producer)
Must be implemented to actually return the cached value, or produce a new one if not present
-
getKeys
protected abstract Collection<K> getKeys(Predicate<K> predicate)
-
-