Package org.cyclos.impl.utils.cache
Class CacheHandlerImpl
- java.lang.Object
-
- org.cyclos.impl.utils.cache.CacheHandlerImpl
-
- All Implemented Interfaces:
CacheHandler,CacheHandlerImplementor
- Direct Known Subclasses:
GuavaCacheHandlerImpl
public abstract class CacheHandlerImpl extends Object implements CacheHandlerImplementor
ACacheHandlerimplementation which configures Guava caches
-
-
Field Summary
Fields Modifier and Type Field Description static StringLOCAL_CACHE
-
Constructor Summary
Constructors Constructor Description CacheHandlerImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidapply(TreeMap<CacheType<? extends Serializable,? extends Serializable>,CacheOperation> operations)Apply the given cache operations for eachCacheType.protected <V,K>
com.google.common.cache.Cache<K,V>createGuavaCache(String name)voiddestroy()<K extends Serializable,V extends Serializable>
Cache<K,V>getCache(CacheType<K,V> type)Returns theCacheimplementation for the given type<K extends Serializable,V extends Serializable>
Cache<K,V>getCacheIfInitialized(CacheType<K,V> type)Returns theCacheimplementation for the given type if it has already been initialized, or null otherwisecom.google.common.cache.Cache<Object,Object>getLocalCache()The local cache is a general-purpose Guava cache that can be used to store data in a cluster will never be distributedprotected abstract <K extends Serializable,V extends Serializable>
Cache<K,V>initCache(CacheType<K,V> type)voidinitialize()booleanisSkipCache()Returns whether this cache handler is temporarily skipping caches<K extends Serializable,V extends Serializable>
voidscheduleClear(CacheType<K,V> type)Schedules a cache clear to be executed after the current transaction has been committed (important to prevent the cache from being reloaded by another thread before the current transaction is committed, populating the cache with a stale value)<K extends Serializable,V extends Serializable>
voidscheduleEvict(CacheType<K,V> type, Set<K> keys)Schedules the eviction of the given cache keys after the current transaction has been committed (important to prevent the cache from being reloaded by another thread before the current transaction is committed, populating the cache with a stale value)<K extends Serializable,V extends Serializable>
voidscheduleEvict(CacheType<K,V> type, K key)Schedules the eviction of an specific cache key after the current transaction has been committed (important to prevent the cache from being reloaded by another thread before the current transaction is committed, populating the cache with a stale value)<K extends Serializable,V extends Serializable>
voidschedulePartialEvict(CacheType<K,V> type, SerializablePredicate<K> predicate)Schedules the eviction of the keys matching the given predicate after the current transaction has been committed (important to prevent the cache from being reloaded by another thread before the current transaction is committed, populating the cache with a stale value)voidsetSkipCache(boolean skipCache)Sets this cache handler to temporarily skip any cache (true) or to use caches normally (false)
-
-
-
Field Detail
-
LOCAL_CACHE
public static final String LOCAL_CACHE
- See Also:
- Constant Field Values
-
-
Method Detail
-
apply
public void apply(TreeMap<CacheType<? extends Serializable,? extends Serializable>,CacheOperation> operations)
Description copied from interface:CacheHandlerApply the given cache operations for eachCacheType.- Specified by:
applyin interfaceCacheHandler
-
destroy
@PreDestroy public void destroy()
-
getCache
public <K extends Serializable,V extends Serializable> Cache<K,V> getCache(CacheType<K,V> type)
Description copied from interface:CacheHandlerReturns theCacheimplementation for the given type- Specified by:
getCachein interfaceCacheHandler
-
getCacheIfInitialized
public <K extends Serializable,V extends Serializable> Cache<K,V> getCacheIfInitialized(CacheType<K,V> type)
Description copied from interface:CacheHandlerReturns theCacheimplementation for the given type if it has already been initialized, or null otherwise- Specified by:
getCacheIfInitializedin interfaceCacheHandler
-
getLocalCache
public com.google.common.cache.Cache<Object,Object> getLocalCache()
Description copied from interface:CacheHandlerThe local cache is a general-purpose Guava cache that can be used to store data in a cluster will never be distributed- Specified by:
getLocalCachein interfaceCacheHandler
-
initialize
@PostConstruct public void initialize()
-
isSkipCache
public boolean isSkipCache()
Description copied from interface:CacheHandlerImplementorReturns whether this cache handler is temporarily skipping caches- Specified by:
isSkipCachein interfaceCacheHandlerImplementor
-
scheduleClear
public <K extends Serializable,V extends Serializable> void scheduleClear(CacheType<K,V> type)
Description copied from interface:CacheHandlerSchedules a cache clear to be executed after the current transaction has been committed (important to prevent the cache from being reloaded by another thread before the current transaction is committed, populating the cache with a stale value)- Specified by:
scheduleClearin interfaceCacheHandler
-
scheduleEvict
public <K extends Serializable,V extends Serializable> void scheduleEvict(CacheType<K,V> type, K key)
Description copied from interface:CacheHandlerSchedules the eviction of an specific cache key after the current transaction has been committed (important to prevent the cache from being reloaded by another thread before the current transaction is committed, populating the cache with a stale value)- Specified by:
scheduleEvictin interfaceCacheHandler
-
scheduleEvict
public <K extends Serializable,V extends Serializable> void scheduleEvict(CacheType<K,V> type, Set<K> keys)
Description copied from interface:CacheHandlerSchedules the eviction of the given cache keys after the current transaction has been committed (important to prevent the cache from being reloaded by another thread before the current transaction is committed, populating the cache with a stale value)- Specified by:
scheduleEvictin interfaceCacheHandler
-
schedulePartialEvict
public <K extends Serializable,V extends Serializable> void schedulePartialEvict(CacheType<K,V> type, SerializablePredicate<K> predicate)
Description copied from interface:CacheHandlerSchedules the eviction of the keys matching the given predicate after the current transaction has been committed (important to prevent the cache from being reloaded by another thread before the current transaction is committed, populating the cache with a stale value)- Specified by:
schedulePartialEvictin interfaceCacheHandler
-
setSkipCache
public void setSkipCache(boolean skipCache)
Description copied from interface:CacheHandlerImplementorSets this cache handler to temporarily skip any cache (true) or to use caches normally (false)- Specified by:
setSkipCachein interfaceCacheHandlerImplementor
-
createGuavaCache
protected <V,K> com.google.common.cache.Cache<K,V> createGuavaCache(String name)
-
initCache
protected abstract <K extends Serializable,V extends Serializable> Cache<K,V> initCache(CacheType<K,V> type)
-
-