Top Description Fields Constructors Methods
net.sf.ehcache.constructs.refreshahead

public Class RefreshAheadCache

extends EhcacheDecoratorAdapter
Class Inheritance
Imports
net.sf.ehcache.Cache, .CacheException, .Ehcache, .Element, .Status, net.sf.ehcache.config.CacheConfiguration, .PersistenceConfiguration, .PersistenceConfiguration.Strategy, .TerracottaConfiguration, .TerracottaConfiguration.Consistency, net.sf.ehcache.constructs.EhcacheDecoratorAdapter, net.sf.ehcache.constructs.refreshahead.ThreadedWorkQueue.BatchWorker, net.sf.ehcache.extension.CacheExtension, net.sf.ehcache.loader.CacheLoader, net.sf.ehcache.statistics.extended.ExtendedStatistics, net.sf.ehcache.store.MemoryStoreEvictionPolicy, net.sf.ehcache.util.VmUtils, java.io.Serializable, java.util.Collection, .Collections, .HashSet, .Map, .Set, java.util.concurrent.ThreadFactory, .TimeUnit, java.util.concurrent.atomic.AtomicLong

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

Modifier and TypeField and Description
private static final int
private static final Object
private final RefreshAheadCacheConfiguration
private final AtomicLong
private volatile ThreadedWorkQueue<Object>
private volatile Ehcache
private CacheConfiguration
Inherited from net.sf.ehcache.constructs.EhcacheDecoratorAdapter:
underlyingCache

Constructor Summary

AccessConstructor and Description
public
RefreshAheadCache(Ehcache adaptedCache, RefreshAheadCacheConfiguration refreshConfig)

Create a Refresh Ahead Cache Adaptor with the specified configuration.

Method Summary

Modifier and TypeMethod and Description
private boolean
checkForRefresh(Element elem, long accessTime, long timeToRefreshMillis)

public static Set<ExtendedStatistics.Statistic<Number>>

Returns:

the set
findBacklogStatistic
(Ehcache
the cache
cache
)

Find backlog statistic.

public static Set<ExtendedStatistics.Statistic<Number>>

Returns:

the set
findDroppedStatistic
(Ehcache
the cache
cache
)

Find dropped statistic.

public static Set<ExtendedStatistics.Statistic<Number>>

Returns:

the set
findOfferStatistic
(Ehcache
the cache this statistic is attached to.
cache
)

Find offer statistic.

public static Set<ExtendedStatistics.Statistic<Number>>

Returns:

the set
findProcessedStatistic
(Ehcache
the cache
cache
)

Find processed statistic.

public static Set<ExtendedStatistics.Statistic<Number>>

Returns:

the set
findRefreshedStatistic
(Ehcache
the cache this statistic is attached to.
cache
)

Find refreshed counter statistic.

public Element
get(Object
an Object value
key
)

Overrides net.sf.ehcache.constructs.EhcacheDecoratorAdapter.get.

Implements net.sf.ehcache.Ehcache.get.

Gets an element from the cache.
public Element
get(Serializable
a serializable value
key
)

Overrides net.sf.ehcache.constructs.EhcacheDecoratorAdapter.get.

Implements net.sf.ehcache.Ehcache.get.

Gets an element from the cache.
public long

Returns:

the backlog count
getBacklogCount
()

Gets backlog count.

public long

Returns:

the dropped count
getDroppedCount
()

Gets dropped count.

public String
public long

Returns:

the offer count
getOfferCount
()

Gets offer count.

public long

Returns:

the processed count
getProcessedCount
()

Gets processed count.

public long
getRefreshSuccessCount()

number of refreshes processed locally.

private void
private void
private void
private void
possiblyTriggerRefresh(Element elem, long timeToRefreshMillis)

Inherited from net.sf.ehcache.constructs.EhcacheDecoratorAdapter:
acquireReadLockOnKeyacquireWriteLockOnKeyaddPropertyChangeListenerbootstrapcalculateInMemorySizecalculateOffHeapSizecalculateOnDiskSizeclonecreateQuerydisableDynamicFeaturesdisposeevictExpiredElementsflushgetAllgetAllWithLoadergetBootstrapCacheLoadergetCacheConfigurationgetCacheEventNotificationServicegetCacheExceptionHandlergetCacheManagergetDiskStoreSizegetGuidgetInternalContextgetKeysgetKeysNoDuplicateCheckgetKeysWithExpiryCheckgetMemoryStoreSizegetOffHeapStoreSizegetQuietgetQuietgetRegisteredCacheExtensionsgetRegisteredCacheLoadersgetRegisteredCacheWritergetSearchAttributegetSearchAttributesgetSizegetStatisticsgetStatusgetWithLoadergetWriterManagerhasAbortedSizeOfinitialiseisClusterBulkLoadEnabledisClusterCoherentisDisabledisElementInMemoryisElementInMemoryisElementOnDiskisElementOnDiskisExpiredisKeyInCacheisNodeBulkLoadEnabledisNodeCoherentisReadLockedByCurrentThreadisSearchableisValueInCacheisWriteLockedByCurrentThreadloadloadAllputputputAllputIfAbsentputIfAbsentputQuietputWithWriterrecalculateSizeregisterCacheExtensionregisterCacheLoaderregisterCacheWriterregisterDynamicAttributesExtractorreleaseReadLockOnKeyreleaseWriteLockOnKeyremoveremoveremoveremoveremoveAllremoveAllremoveAllremoveAllremoveAndReturnElementremoveElementremovePropertyChangeListenerremoveQuietremoveQuietremoveWithWriterreplacereplacesetBootstrapCacheLoadersetCacheExceptionHandlersetCacheManagersetDisabledsetNamesetNodeBulkLoadEnabledsetNodeCoherentsetTransactionManagerLookuptoStringtryReadLockOnKeytryWriteLockOnKeyunregisterCacheExtensionunregisterCacheLoaderunregisterCacheWriterwaitUntilClusterBulkLoadCompletewaitUntilClusterCoherent

Field Detail

DEFAULT_SUPPORT_TTL_SECONDSback to summary
private static final int DEFAULT_SUPPORT_TTL_SECONDS
REFRESH_VALUEback to summary
private static final Object REFRESH_VALUE
refreshAheadConfigback to summary
private final RefreshAheadCacheConfiguration refreshAheadConfig
refreshSuccessCountback to summary
private final AtomicLong refreshSuccessCount
refreshWorkQueueback to summary
private volatile ThreadedWorkQueue<Object> refreshWorkQueue
supportCacheback to summary
private volatile Ehcache supportCache
supportConfigback to summary
private CacheConfiguration supportConfig

Constructor Detail

RefreshAheadCacheback to summary
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.

Method Detail

checkForRefreshback to summary
private boolean checkForRefresh(Element elem, long accessTime, long timeToRefreshMillis)
findBacklogStatisticback to summary
public static Set<ExtendedStatistics.Statistic<Number>> findBacklogStatistic(Ehcache cache)

Find backlog statistic.

Parameters
cache:Ehcache

the cache

Returns:Set<ExtendedStatistics.Statistic<Number>>

the set

findDroppedStatisticback to summary
public static Set<ExtendedStatistics.Statistic<Number>> findDroppedStatistic(Ehcache cache)

Find dropped statistic.

Parameters
cache:Ehcache

the cache

Returns:Set<ExtendedStatistics.Statistic<Number>>

the set

findOfferStatisticback to summary
public static Set<ExtendedStatistics.Statistic<Number>> findOfferStatistic(Ehcache cache)

Find offer statistic.

Parameters
cache:Ehcache

the cache this statistic is attached to.

Returns:Set<ExtendedStatistics.Statistic<Number>>

the set

findProcessedStatisticback to summary
public static Set<ExtendedStatistics.Statistic<Number>> findProcessedStatistic(Ehcache cache)

Find processed statistic.

Parameters
cache:Ehcache

the cache

Returns:Set<ExtendedStatistics.Statistic<Number>>

the set

findRefreshedStatisticback to summary
public static Set<ExtendedStatistics.Statistic<Number>> findRefreshedStatistic(Ehcache cache)

Find refreshed counter statistic.

Parameters
cache:Ehcache

the cache this statistic is attached to.

Returns:Set<ExtendedStatistics.Statistic<Number>>

the set

getback to summary
public Element get(Object key) throws IllegalStateException, CacheException

Overrides net.sf.ehcache.constructs.EhcacheDecoratorAdapter.get.

Implements net.sf.ehcache.Ehcache.get.

Doc from net.sf.ehcache.constructs.EhcacheDecoratorAdapter.get.

Gets an element from the cache. Updates Element Statistics

Note that the Element's lastAccessTime is always the time of this get. Use getQuiet(Object) to peek into the Element to see its last access time with get

Parameters
key:Object

Doc from net.sf.ehcache.Ehcache.get.

an Object value

Returns:Element

Doc from net.sf.ehcache.Ehcache.get.

the element, or null, if it does not exist.

Annotations
@Override
Exceptions
IllegalStateException:

Doc from net.sf.ehcache.Ehcache.get.

if the cache is not net.sf.ehcache.Status#STATUS_ALIVE

getback to summary
public Element get(Serializable key) throws IllegalStateException, CacheException

Overrides net.sf.ehcache.constructs.EhcacheDecoratorAdapter.get.

Implements net.sf.ehcache.Ehcache.get.

Doc from net.sf.ehcache.constructs.EhcacheDecoratorAdapter.get.

Gets an element from the cache. Updates Element Statistics

Note that the Element's lastAccessTime is always the time of this get. Use getQuiet(Object) to peak into the Element to see its last access time with get

Parameters
key:Serializable

Doc from net.sf.ehcache.Ehcache.get.

a serializable value

Returns:Element

Doc from net.sf.ehcache.Ehcache.get.

the element, or null, if it does not exist.

Annotations
@Override
Exceptions
IllegalStateException:

Doc from net.sf.ehcache.Ehcache.get.

if the cache is not net.sf.ehcache.Status#STATUS_ALIVE

getBacklogCountback to summary
public long getBacklogCount()

Gets backlog count.

Returns:long

the backlog count

Annotations
@Statistic
name:backlog
tags:refreshahead
getDroppedCountback to summary
public long getDroppedCount()

Gets dropped count.

Returns:long

the dropped count

Annotations
@Statistic
name:dropped
tags:refreshahead
getNameback to summary
public String getName()

Overrides net.sf.ehcache.constructs.EhcacheDecoratorAdapter.getName.

Implements net.sf.ehcache.Ehcache.getName.

Doc from net.sf.ehcache.constructs.EhcacheDecoratorAdapter.getName.

Gets the cache name.

Returns:String

Doc from net.sf.ehcache.Ehcache.getName.

the name

Annotations
@Override
getOfferCountback to summary
public long getOfferCount()

Gets offer count.

Returns:long

the offer count

Annotations
@Statistic
name:offered
tags:refreshahead
getProcessedCountback to summary
public long getProcessedCount()

Gets processed count.

Returns:long

the processed count

Annotations
@Statistic
name:processed
tags:refreshahead
getRefreshSuccessCountback to summary
public long getRefreshSuccessCount()

number of refreshes processed locally.

Annotations
@Statistic
name:refreshed
tags:refreshahead
initSupportCacheback to summary
private void initSupportCache()
initWorkQueueback to summary
private void initWorkQueue()
localDisposeback to summary
private void localDispose() throws IllegalStateException
possiblyTriggerRefreshback to summary
private void possiblyTriggerRefresh(Element elem, long timeToRefreshMillis)