Package com.atlassian.cache.ehcache
Class LoadingCache<K,V>
java.lang.Object
net.sf.ehcache.constructs.EhcacheDecoratorAdapter
net.sf.ehcache.constructs.blocking.BlockingCache
com.atlassian.cache.ehcache.LoadingCache<K,V>
- Type Parameters:
K- the cache's key typeV- the cache's value type
- All Implemented Interfaces:
Cloneable,net.sf.ehcache.Ehcache,net.sf.ehcache.terracotta.InternalEhcache
public class LoadingCache<K,V>
extends net.sf.ehcache.constructs.blocking.BlockingCache
A rewrite of
SelfPopulatingCache with stronger concurrency guarantees.
We don't lock on loadValueAndReleaseLock(Object), instead we put a flag for each loading operation.
If a remove(Object) operation happens during load operation and before putting the value in to the cache,
newly loaded value will not be put into the cache and only returned to the caller.
Subsequent calls with the same key will trigger a new load operation thus ensuring eventual consistency.
We only lock for actually putting the value into the cache, not loading.- See Also:
-
BlockingCacheSynchronizedLoadingCacheDecorator
-
Field Summary
Fields inherited from class net.sf.ehcache.constructs.blocking.BlockingCache
timeoutMillisFields inherited from class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
underlyingCache -
Constructor Summary
ConstructorsConstructorDescriptionLoadingCache(SynchronizedLoadingCacheDecorator cache, CacheLoader<K, V> loader) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidnet.sf.ehcache.Elementbooleanbooleanvoidvoidbooleanremove(Serializable key) booleanremove(Serializable key, boolean doNotNotifyCacheReplicators) booleanbooleanvoidvoidremoveAll(boolean doNotNotifyCacheReplicators) voidremoveAll(Collection<?> keys) voidremoveAll(Collection<?> keys, boolean doNotNotifyCacheReplicators) booleantryReadLockOnKey(Object key, long timeout) booleantryWriteLockOnKey(Object key, long timeout) Methods inherited from class net.sf.ehcache.constructs.blocking.BlockingCache
get, getAllWithLoader, getCache, getLockForKey, getTimeoutMillis, getWithLoader, liveness, load, loadAll, put, put, putIfAbsent, putIfAbsent, putQuiet, putWithWriter, registerCacheLoader, setTimeoutMillis, unregisterCacheLoaderMethods inherited from class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
addPropertyChangeListener, bootstrap, calculateInMemorySize, calculateOffHeapSize, calculateOnDiskSize, clone, createQuery, disableDynamicFeatures, dispose, evictExpiredElements, flush, getAll, getBootstrapCacheLoader, getCacheConfiguration, getCacheEventNotificationService, getCacheExceptionHandler, getCacheManager, getDiskStoreSize, getGuid, getInternalContext, getKeys, getKeysNoDuplicateCheck, getKeysWithExpiryCheck, getMemoryStoreSize, getName, getOffHeapStoreSize, getQuiet, getQuiet, getRegisteredCacheExtensions, getRegisteredCacheLoaders, getRegisteredCacheWriter, getSearchAttribute, getSearchAttributes, getSize, getStatistics, getStatus, getWriterManager, hasAbortedSizeOf, initialise, isClusterBulkLoadEnabled, isClusterCoherent, isDisabled, isElementInMemory, isElementInMemory, isElementOnDisk, isElementOnDisk, isExpired, isKeyInCache, isNodeBulkLoadEnabled, isNodeCoherent, isSearchable, isValueInCache, putAll, recalculateSize, registerCacheExtension, registerCacheWriter, registerDynamicAttributesExtractor, removeAndReturnElement, removeElement, removePropertyChangeListener, removeQuiet, removeQuiet, removeWithWriter, replace, replace, setBootstrapCacheLoader, setCacheExceptionHandler, setCacheManager, setDisabled, setName, setNodeBulkLoadEnabled, setNodeCoherent, setTransactionManagerLookup, toString, unregisterCacheExtension, unregisterCacheWriter, waitUntilClusterBulkLoadComplete, waitUntilClusterCoherent
-
Constructor Details
-
LoadingCache
public LoadingCache(SynchronizedLoadingCacheDecorator cache, CacheLoader<K, V> loader) throws net.sf.ehcache.CacheException- Throws:
net.sf.ehcache.CacheException
-
-
Method Details
-
acquireReadLockOnKey
- Specified by:
acquireReadLockOnKeyin interfacenet.sf.ehcache.Ehcache- Overrides:
acquireReadLockOnKeyin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
acquireWriteLockOnKey
- Specified by:
acquireWriteLockOnKeyin interfacenet.sf.ehcache.Ehcache- Overrides:
acquireWriteLockOnKeyin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
releaseReadLockOnKey
- Specified by:
releaseReadLockOnKeyin interfacenet.sf.ehcache.Ehcache- Overrides:
releaseReadLockOnKeyin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
releaseWriteLockOnKey
- Specified by:
releaseWriteLockOnKeyin interfacenet.sf.ehcache.Ehcache- Overrides:
releaseWriteLockOnKeyin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
tryReadLockOnKey
- Specified by:
tryReadLockOnKeyin interfacenet.sf.ehcache.Ehcache- Overrides:
tryReadLockOnKeyin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter- Throws:
InterruptedException
-
tryWriteLockOnKey
- Specified by:
tryWriteLockOnKeyin interfacenet.sf.ehcache.Ehcache- Overrides:
tryWriteLockOnKeyin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter- Throws:
InterruptedException
-
isReadLockedByCurrentThread
- Specified by:
isReadLockedByCurrentThreadin interfacenet.sf.ehcache.Ehcache- Overrides:
isReadLockedByCurrentThreadin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
isWriteLockedByCurrentThread
- Specified by:
isWriteLockedByCurrentThreadin interfacenet.sf.ehcache.Ehcache- Overrides:
isWriteLockedByCurrentThreadin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
get
- Specified by:
getin interfacenet.sf.ehcache.Ehcache- Overrides:
getin classnet.sf.ehcache.constructs.blocking.BlockingCache
-
remove
- Specified by:
removein interfacenet.sf.ehcache.Ehcache- Overrides:
removein classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
remove
- Specified by:
removein interfacenet.sf.ehcache.Ehcache- Overrides:
removein classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
remove
- Specified by:
removein interfacenet.sf.ehcache.Ehcache- Overrides:
removein classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
remove
- Specified by:
removein interfacenet.sf.ehcache.Ehcache- Overrides:
removein classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
removeAll
- Specified by:
removeAllin interfacenet.sf.ehcache.Ehcache- Overrides:
removeAllin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
removeAll
- Specified by:
removeAllin interfacenet.sf.ehcache.Ehcache- Overrides:
removeAllin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
removeAll
public void removeAll()- Specified by:
removeAllin interfacenet.sf.ehcache.Ehcache- Overrides:
removeAllin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
removeAll
public void removeAll(boolean doNotNotifyCacheReplicators) - Specified by:
removeAllin interfacenet.sf.ehcache.Ehcache- Overrides:
removeAllin classnet.sf.ehcache.constructs.EhcacheDecoratorAdapter
-