Package org.cache2k.core
Class WiredCache<K,V>
- java.lang.Object
-
- org.cache2k.core.BaseCache<K,V>
-
- org.cache2k.core.WiredCache<K,V>
-
- All Implemented Interfaces:
AutoCloseable,org.cache2k.Cache<K,V>,InternalCache<K,V>,InternalCacheCloseContext,InternalEvictionListener<K,V>,TimerEventListener<K,V>,org.cache2k.DataAware<K,V>,org.cache2k.KeyValueSource<K,V>
public class WiredCache<K,V> extends BaseCache<K,V> implements InternalEvictionListener<K,V>
A cache implementation that builds on a heap cache and coordinates with additional attachments like storage, listeners and a writer.- Author:
- Jens Wilke
-
-
Field Summary
-
Fields inherited from interface org.cache2k.core.eviction.InternalEvictionListener
NO_OPERATION
-
-
Constructor Summary
Constructors Constructor Description WiredCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancelTimerJobs()used from the cache manager for shutdownvoidcheckIntegrity()Cache checks its internal integrity.voidclear()voidclose()VcomputeIfAbsent(K key, Function<? super K,? extends V> function)booleancontainsAndRemove(K key)booleancontainsKey(K key)protected <R> EntryAction<K,V,R>createEntryAction(K key, Entry<K,V> e, Semantic<K,V,R> op)protected <R> org.cache2k.core.WiredCache.MyEntryAction<R>createFireAndForgetAction(Entry<K,V> e, Semantic<K,V,R> op)Vget(K key)Map<K,V>getAll(Iterable<? extends K> requestedKeys)This takes four different execution paths depending on cache setup and state: no loader and/or all data present in heap, async or async bulk, parallel single load, bulk load.org.cache2k.CacheManagergetCacheManager()The cache managerorg.cache2k.operation.TimeReferencegetClock()Time reference for the cache.CommonMetricsgetCommonMetrics()InternalCacheInfogetConsistentInfo()Generate fresh statistics within a global cache lock.org.cache2k.CacheEntry<K,V>getEntry(K key)StringgetEntryState(K key)EvictiongetEviction()ExecutorgetExecutor()HeapCachegetHeapCache()For testingInternalCacheInfogetInfo()Return cache statistic counters.org.cache2k.config.CacheTypegetKeyType()LoggetLog()used from the cache managerStringgetName()Designation of target for logging and exceptions.longgetTotalEntryCount()This method is used forConcurrentMapWrapper.size()org.cache2k.Cache<K,V>getUserCache()Cache used by user, eventually wrapped.org.cache2k.config.CacheTypegetValueType()voidinit()<R> Rinvoke(K key, org.cache2k.processor.EntryProcessor<K,V,R> processor)<@Nullable R>
Map<K,org.cache2k.processor.EntryProcessingResult<R>>invokeAll(Iterable<? extends K> keys, org.cache2k.processor.EntryProcessor<K,V,@Nullable R> entryProcessor)booleanisClosed()booleanisLoaderPresent()booleanisNullValuePermitted()booleanisWeigherPresent()Iterator<org.cache2k.CacheEntry<K,V>>iterator()CompletableFuture<Void>loadAll(Iterable<? extends K> keys)voidlogAndCountInternalException(String s, Throwable t)voidonEvictionFromHeap(Entry<K,V> e)Calls eviction listeners.Vpeek(K key)Map<K,V>peekAll(Iterable<? extends K> keys)We need to deal with possible null values and exceptions.VpeekAndPut(K key, V value)VpeekAndRemove(K key)VpeekAndReplace(K key, V value)org.cache2k.CacheEntry<K,V>peekEntry(K key)voidput(K key, V value)voidputAll(Map<? extends K,? extends V> m)booleanputIfAbsent(K key, V value)CompletableFuture<Void>reloadAll(Iterable<? extends K> keys)voidremove(K key)booleanremoveIfEquals(K key, V value)booleanreplace(K key, V newValue)booleanreplaceIfEquals(K key, V oldValue, V newValue)org.cache2k.CacheEntry<K,V>returnCacheEntry(ExaminationEntry<K,V> e)voidtimerEventExpireEntry(Entry<K,V> e, Object task)If not expired yet, negate time to enforce time checks, schedule task for expiry otherwise.voidtimerEventProbationTerminated(Entry<K,V> e, Object task)voidtimerEventRefresh(Entry<K,V> e, Object task)Starts a refresh operation or expires if no threads in the loader thread pool are available.-
Methods inherited from class org.cache2k.core.BaseCache
asMap, closeCustomization, entries, execute, execute, expireAt, getQualifiedName, keys, removeAll, removeAll, requestInterface, toString
-
-
-
-
Method Detail
-
getLog
public Log getLog()
Description copied from interface:InternalCacheused from the cache manager- Specified by:
getLogin interfaceInternalCache<K,V>
-
getHeapCache
public HeapCache getHeapCache()
For testing
-
getClock
public org.cache2k.operation.TimeReference getClock()
Description copied from interface:InternalCacheTime reference for the cache.- Specified by:
getClockin interfaceInternalCache<K,V>
-
isNullValuePermitted
public boolean isNullValuePermitted()
- Specified by:
isNullValuePermittedin interfaceInternalCache<K,V>
-
getName
public String getName()
Description copied from interface:TimerEventListenerDesignation of target for logging and exceptions.- Specified by:
getNamein interfaceorg.cache2k.Cache<K,V>- Specified by:
getNamein interfaceInternalCacheCloseContext- Specified by:
getNamein interfaceTimerEventListener<K,V>
-
getKeyType
public org.cache2k.config.CacheType getKeyType()
- Specified by:
getKeyTypein interfaceInternalCache<K,V>
-
getValueType
public org.cache2k.config.CacheType getValueType()
- Specified by:
getValueTypein interfaceInternalCache<K,V>
-
getCacheManager
public org.cache2k.CacheManager getCacheManager()
Description copied from interface:InternalCacheCloseContextThe cache manager- Specified by:
getCacheManagerin interfaceorg.cache2k.Cache<K,V>- Specified by:
getCacheManagerin interfaceInternalCacheCloseContext
-
containsKey
public boolean containsKey(K key)
-
containsAndRemove
public boolean containsAndRemove(K key)
-
loadAll
public CompletableFuture<Void> loadAll(Iterable<? extends K> keys)
-
reloadAll
public CompletableFuture<Void> reloadAll(Iterable<? extends K> keys)
-
createFireAndForgetAction
protected <R> org.cache2k.core.WiredCache.MyEntryAction<R> createFireAndForgetAction(Entry<K,V> e, Semantic<K,V,R> op)
- Specified by:
createFireAndForgetActionin classBaseCache<K,V>
-
getExecutor
public Executor getExecutor()
- Specified by:
getExecutorin classBaseCache<K,V>
-
isWeigherPresent
public boolean isWeigherPresent()
- Specified by:
isWeigherPresentin interfaceInternalCache<K,V>
-
isLoaderPresent
public boolean isLoaderPresent()
- Specified by:
isLoaderPresentin interfaceInternalCache<K,V>
-
getAll
public Map<K,V> getAll(Iterable<? extends K> requestedKeys)
This takes four different execution paths depending on cache setup and state: no loader and/or all data present in heap, async or async bulk, parallel single load, bulk load.
-
getTotalEntryCount
public long getTotalEntryCount()
Description copied from interface:InternalCacheThis method is used forConcurrentMapWrapper.size()- Specified by:
getTotalEntryCountin interfaceInternalCache<K,V>
-
invokeAll
public <@Nullable R> Map<K,org.cache2k.processor.EntryProcessingResult<R>> invokeAll(Iterable<? extends K> keys, org.cache2k.processor.EntryProcessor<K,V,@Nullable R> entryProcessor)
-
peekAll
public Map<K,V> peekAll(Iterable<? extends K> keys)
We need to deal with possible null values and exceptions. This is a simple placeholder implementation that covers it all by working on the entry.
-
getConsistentInfo
public InternalCacheInfo getConsistentInfo()
Description copied from interface:InternalCacheGenerate fresh statistics within a global cache lock. This version is used by internal consistency tests. This method is not intended to be called at high frequencies or for attaching monitoring or logging. Use theInternalCache.getInfo()method for requesting information for monitoring.- Specified by:
getConsistentInfoin interfaceInternalCache<K,V>
-
getInfo
public InternalCacheInfo getInfo()
Description copied from interface:InternalCacheReturn cache statistic counters. This method is intended for regular statistics polling. No extensive locking is performed to extract a consistent set of counters.- Specified by:
getInfoin interfaceInternalCache<K,V>
-
getCommonMetrics
public CommonMetrics getCommonMetrics()
- Specified by:
getCommonMetricsin interfaceInternalCache<K,V>
-
logAndCountInternalException
public void logAndCountInternalException(String s, Throwable t)
- Specified by:
logAndCountInternalExceptionin interfaceInternalCache<K,V>
-
checkIntegrity
public void checkIntegrity()
Description copied from interface:InternalCacheCache checks its internal integrity. This is a expansive operation because it may traverse all cache entries. Used for testing.- Specified by:
checkIntegrityin interfaceInternalCache<K,V>
-
init
public void init()
-
cancelTimerJobs
public void cancelTimerJobs()
Description copied from interface:InternalCacheused from the cache manager for shutdown- Specified by:
cancelTimerJobsin interfaceInternalCache<K,V>
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceorg.cache2k.Cache<K,V>
-
returnCacheEntry
public org.cache2k.CacheEntry<K,V> returnCacheEntry(ExaminationEntry<K,V> e)
- Specified by:
returnCacheEntryin interfaceInternalCache<K,V>
-
getEviction
public Eviction getEviction()
- Specified by:
getEvictionin interfaceInternalCache<K,V>
-
onEvictionFromHeap
public void onEvictionFromHeap(Entry<K,V> e)
Calls eviction listeners.- Specified by:
onEvictionFromHeapin interfaceInternalEvictionListener<K,V>
-
createEntryAction
protected <R> EntryAction<K,V,R> createEntryAction(K key, Entry<K,V> e, Semantic<K,V,R> op)
- Specified by:
createEntryActionin classBaseCache<K,V>
-
getEntryState
public String getEntryState(K key)
- Specified by:
getEntryStatein interfaceInternalCache<K,V>
-
timerEventExpireEntry
public void timerEventExpireEntry(Entry<K,V> e, Object task)
If not expired yet, negate time to enforce time checks, schedule task for expiry otherwise. Semantics double withHeapCache.timerEventExpireEntry(Entry, Object)- Specified by:
timerEventExpireEntryin interfaceTimerEventListener<K,V>task- timer task as returned byEntry.getTask()to check whether the timer task is still valid after we obtained the entry lock
-
timerEventRefresh
public void timerEventRefresh(Entry<K,V> e, Object task)
Starts a refresh operation or expires if no threads in the loader thread pool are available. If no async loader is available we execute the synchronous loader via the loader thread pool.- Specified by:
timerEventRefreshin interfaceTimerEventListener<K,V>- Parameters:
e- seeTimerEventListener.timerEventExpireEntry(Entry, Object)task- seeTimerEventListener.timerEventExpireEntry(Entry, Object)
-
timerEventProbationTerminated
public void timerEventProbationTerminated(Entry<K,V> e, Object task)
- Specified by:
timerEventProbationTerminatedin interfaceTimerEventListener<K,V>- Parameters:
e- seeTimerEventListener.timerEventExpireEntry(Entry, Object)task- seeTimerEventListener.timerEventExpireEntry(Entry, Object)
-
getUserCache
public org.cache2k.Cache<K,V> getUserCache()
Description copied from interface:InternalCacheCache used by user, eventually wrapped. We only need to know our "wrapped self" in case events are send, so only implemented by WiredCache.- Specified by:
getUserCachein interfaceInternalCache<K,V>
-
-