Class RefreshAheadCache
- java.lang.Object
-
- net.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
- net.sf.ehcache.constructs.refreshahead.RefreshAheadCache
-
- All Implemented Interfaces:
java.lang.Cloneable,Ehcache,InternalEhcache
public class RefreshAheadCache extends EhcacheDecoratorAdapter
A cache decorator which implements read ahead refreshing. Read ahead occurs when a cache entry is accessed prior to its expiration, and triggers a reload of the value in the background.A significant attempt is made to ensure only one node of the cache works on a specific key at a time. There is no guarantee that every triggered refresh ahead case will be processed. As the maximum number of backlog entries is reached, refresh ahead requests will be dropped silently.
Provided the
Number of threads per node * Number of nodes < the maximum backlog, only one node in the cluster will refresh a given key at a time.- Author:
- cschanck
-
-
Field Summary
-
Fields inherited from class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
underlyingCache
-
-
Constructor Summary
Constructors Constructor Description RefreshAheadCache(Ehcache adaptedCache, RefreshAheadCacheConfiguration refreshConfig)Create a Refresh Ahead Cache Adaptor with the specified configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>>findBacklogStatistic(Ehcache cache)Find backlog statistic.static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>>findDroppedStatistic(Ehcache cache)Find dropped statistic.static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>>findOfferStatistic(Ehcache cache)Find offer statistic.static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>>findProcessedStatistic(Ehcache cache)Find processed statistic.static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>>findRefreshedStatistic(Ehcache cache)Find refreshed counter statistic.Elementget(java.io.Serializable key)Gets an element from the cache.Elementget(java.lang.Object key)Gets an element from the cache.longgetBacklogCount()Gets backlog count.longgetDroppedCount()Gets dropped count.java.lang.StringgetName()Gets the cache name.longgetOfferCount()Gets offer count.longgetProcessedCount()Gets processed count.longgetRefreshSuccessCount()number of refreshes processed locally.-
Methods inherited from class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
acquireReadLockOnKey, acquireWriteLockOnKey, addPropertyChangeListener, bootstrap, calculateInMemorySize, calculateOffHeapSize, calculateOnDiskSize, clone, createQuery, disableDynamicFeatures, dispose, evictExpiredElements, flush, getAll, getAllWithLoader, getBootstrapCacheLoader, getCacheConfiguration, getCacheEventNotificationService, getCacheExceptionHandler, getCacheManager, getDiskStoreSize, getGuid, getInternalContext, getKeys, getKeysNoDuplicateCheck, getKeysWithExpiryCheck, getMemoryStoreSize, getOffHeapStoreSize, getQuiet, getQuiet, getRegisteredCacheExtensions, getRegisteredCacheLoaders, getRegisteredCacheWriter, getSearchAttribute, getSearchAttributes, getSize, getStatistics, getStatus, getWithLoader, getWriterManager, hasAbortedSizeOf, initialise, isClusterBulkLoadEnabled, isClusterCoherent, isDisabled, isElementInMemory, isElementInMemory, isElementOnDisk, isElementOnDisk, isExpired, isKeyInCache, isNodeBulkLoadEnabled, isNodeCoherent, isReadLockedByCurrentThread, isSearchable, isValueInCache, isWriteLockedByCurrentThread, load, loadAll, put, put, putAll, putIfAbsent, putIfAbsent, putQuiet, putWithWriter, recalculateSize, registerCacheExtension, registerCacheLoader, registerCacheWriter, registerDynamicAttributesExtractor, releaseReadLockOnKey, releaseWriteLockOnKey, remove, remove, remove, remove, removeAll, removeAll, removeAll, removeAll, removeAndReturnElement, removeElement, removePropertyChangeListener, removeQuiet, removeQuiet, removeWithWriter, replace, replace, setBootstrapCacheLoader, setCacheExceptionHandler, setCacheManager, setDisabled, setName, setNodeBulkLoadEnabled, setNodeCoherent, setTransactionManagerLookup, toString, tryReadLockOnKey, tryWriteLockOnKey, unregisterCacheExtension, unregisterCacheLoader, unregisterCacheWriter, waitUntilClusterBulkLoadComplete, waitUntilClusterCoherent
-
-
-
-
Constructor Detail
-
RefreshAheadCache
public RefreshAheadCache(Ehcache adaptedCache, RefreshAheadCacheConfiguration refreshConfig)
Create a Refresh Ahead Cache Adaptor with the specified configuration. An auxiliary EhCache Cache will be created for the purposes of synchronization, so only one node in a clustered environment will refresh a key at a given time.- Parameters:
adaptedCache-refreshConfig-
-
-
Method Detail
-
get
public Element get(java.lang.Object key) throws java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterGets an element from the cache. Updates Element StatisticsNote that the Element's lastAccessTime is always the time of this get. Use
Ehcache.getQuiet(Object)to peek into the Element to see its last access time with get- Specified by:
getin interfaceEhcache- Overrides:
getin classEhcacheDecoratorAdapter- Parameters:
key- an Object value- Returns:
- the element, or null, if it does not exist.
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- See Also:
Ehcache.isExpired(net.sf.ehcache.Element)
-
get
public Element get(java.io.Serializable key) throws java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterGets an element from the cache. Updates Element StatisticsNote that the Element's lastAccessTime is always the time of this get. Use
Ehcache.getQuiet(Object)to peak into the Element to see its last access time with get- Specified by:
getin interfaceEhcache- Overrides:
getin classEhcacheDecoratorAdapter- Parameters:
key- a serializable value- Returns:
- the element, or null, if it does not exist.
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- See Also:
Ehcache.isExpired(net.sf.ehcache.Element)
-
getRefreshSuccessCount
public long getRefreshSuccessCount()
number of refreshes processed locally.
-
getName
public java.lang.String getName()
Description copied from class:EhcacheDecoratorAdapterGets the cache name.- Specified by:
getNamein interfaceEhcache- Overrides:
getNamein classEhcacheDecoratorAdapter- Returns:
- the name
-
getOfferCount
public long getOfferCount()
Gets offer count.- Returns:
- the offer count
-
getDroppedCount
public long getDroppedCount()
Gets dropped count.- Returns:
- the dropped count
-
getProcessedCount
public long getProcessedCount()
Gets processed count.- Returns:
- the processed count
-
getBacklogCount
public long getBacklogCount()
Gets backlog count.- Returns:
- the backlog count
-
findRefreshedStatistic
public static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>> findRefreshedStatistic(Ehcache cache)
Find refreshed counter statistic.- Parameters:
cache- the cache this statistic is attached to.- Returns:
- the set
-
findOfferStatistic
public static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>> findOfferStatistic(Ehcache cache)
Find offer statistic.- Parameters:
cache- the cache this statistic is attached to.- Returns:
- the set
-
findDroppedStatistic
public static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>> findDroppedStatistic(Ehcache cache)
Find dropped statistic.- Parameters:
cache- the cache- Returns:
- the set
-
findProcessedStatistic
public static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>> findProcessedStatistic(Ehcache cache)
Find processed statistic.- Parameters:
cache- the cache- Returns:
- the set
-
findBacklogStatistic
public static java.util.Set<ExtendedStatistics.Statistic<java.lang.Number>> findBacklogStatistic(Ehcache cache)
Find backlog statistic.- Parameters:
cache- the cache- Returns:
- the set
-
-