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 type
V - 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:
  • Field Summary

    Fields inherited from class net.sf.ehcache.constructs.blocking.BlockingCache

    timeoutMillis

    Fields inherited from class net.sf.ehcache.constructs.EhcacheDecoratorAdapter

    underlyingCache
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    net.sf.ehcache.Element
    get(Object key)
     
    boolean
     
    boolean
     
    void
     
    void
     
    boolean
     
    boolean
    remove(Serializable key, boolean doNotNotifyCacheReplicators)
     
    boolean
     
    boolean
    remove(Object key, boolean doNotNotifyCacheReplicators)
     
    void
     
    void
    removeAll(boolean doNotNotifyCacheReplicators)
     
    void
     
    void
    removeAll(Collection<?> keys, boolean doNotNotifyCacheReplicators)
     
    boolean
    tryReadLockOnKey(Object key, long timeout)
     
    boolean
    tryWriteLockOnKey(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, unregisterCacheLoader

    Methods 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

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • acquireReadLockOnKey

      public void acquireReadLockOnKey(Object key)
      Specified by:
      acquireReadLockOnKey in interface net.sf.ehcache.Ehcache
      Overrides:
      acquireReadLockOnKey in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • acquireWriteLockOnKey

      public void acquireWriteLockOnKey(Object key)
      Specified by:
      acquireWriteLockOnKey in interface net.sf.ehcache.Ehcache
      Overrides:
      acquireWriteLockOnKey in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • releaseReadLockOnKey

      public void releaseReadLockOnKey(Object key)
      Specified by:
      releaseReadLockOnKey in interface net.sf.ehcache.Ehcache
      Overrides:
      releaseReadLockOnKey in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • releaseWriteLockOnKey

      public void releaseWriteLockOnKey(Object key)
      Specified by:
      releaseWriteLockOnKey in interface net.sf.ehcache.Ehcache
      Overrides:
      releaseWriteLockOnKey in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • tryReadLockOnKey

      public boolean tryReadLockOnKey(Object key, long timeout) throws InterruptedException
      Specified by:
      tryReadLockOnKey in interface net.sf.ehcache.Ehcache
      Overrides:
      tryReadLockOnKey in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
      Throws:
      InterruptedException
    • tryWriteLockOnKey

      public boolean tryWriteLockOnKey(Object key, long timeout) throws InterruptedException
      Specified by:
      tryWriteLockOnKey in interface net.sf.ehcache.Ehcache
      Overrides:
      tryWriteLockOnKey in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
      Throws:
      InterruptedException
    • isReadLockedByCurrentThread

      public boolean isReadLockedByCurrentThread(Object key)
      Specified by:
      isReadLockedByCurrentThread in interface net.sf.ehcache.Ehcache
      Overrides:
      isReadLockedByCurrentThread in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • isWriteLockedByCurrentThread

      public boolean isWriteLockedByCurrentThread(Object key)
      Specified by:
      isWriteLockedByCurrentThread in interface net.sf.ehcache.Ehcache
      Overrides:
      isWriteLockedByCurrentThread in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • get

      public net.sf.ehcache.Element get(Object key)
      Specified by:
      get in interface net.sf.ehcache.Ehcache
      Overrides:
      get in class net.sf.ehcache.constructs.blocking.BlockingCache
    • remove

      public boolean remove(Serializable key, boolean doNotNotifyCacheReplicators)
      Specified by:
      remove in interface net.sf.ehcache.Ehcache
      Overrides:
      remove in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • remove

      public boolean remove(Serializable key)
      Specified by:
      remove in interface net.sf.ehcache.Ehcache
      Overrides:
      remove in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • remove

      public boolean remove(Object key)
      Specified by:
      remove in interface net.sf.ehcache.Ehcache
      Overrides:
      remove in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • remove

      public boolean remove(Object key, boolean doNotNotifyCacheReplicators)
      Specified by:
      remove in interface net.sf.ehcache.Ehcache
      Overrides:
      remove in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • removeAll

      public void removeAll(Collection<?> keys)
      Specified by:
      removeAll in interface net.sf.ehcache.Ehcache
      Overrides:
      removeAll in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • removeAll

      public void removeAll(Collection<?> keys, boolean doNotNotifyCacheReplicators)
      Specified by:
      removeAll in interface net.sf.ehcache.Ehcache
      Overrides:
      removeAll in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • removeAll

      public void removeAll()
      Specified by:
      removeAll in interface net.sf.ehcache.Ehcache
      Overrides:
      removeAll in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
    • removeAll

      public void removeAll(boolean doNotNotifyCacheReplicators)
      Specified by:
      removeAll in interface net.sf.ehcache.Ehcache
      Overrides:
      removeAll in class net.sf.ehcache.constructs.EhcacheDecoratorAdapter