Class UpdatingSelfPopulatingCache
- java.lang.Object
-
- net.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
- net.sf.ehcache.constructs.blocking.BlockingCache
-
- net.sf.ehcache.constructs.blocking.SelfPopulatingCache
-
- net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache
-
- All Implemented Interfaces:
java.lang.Cloneable,Ehcache,InternalEhcache
public class UpdatingSelfPopulatingCache extends SelfPopulatingCache
ACachebacked cache that creates entries on demand.Clients of the cache simply call it without needing knowledge of whether the entry exists in the cache, or whether it needs updating before use.
Thread safety depends on the factory being used. The UpdatingCacheEntryFactory should be made thread safe. In addition users of returned values should not modify their contents.
- Version:
- $Id$
- Author:
- Greg Luck
-
-
Field Summary
-
Fields inherited from class net.sf.ehcache.constructs.blocking.SelfPopulatingCache
factory
-
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 UpdatingSelfPopulatingCache(Ehcache cache, UpdatingCacheEntryFactory factory)Creates a SelfPopulatingCache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Elementget(java.lang.Object key)Looks up an object.voidrefresh()This method should not be used.protected voidupdate(java.lang.Object key)Element can never be null.-
Methods inherited from class net.sf.ehcache.constructs.blocking.SelfPopulatingCache
makeAndCheckElement, refresh, refresh, refresh, refreshElement, refreshElement
-
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
acquireReadLockOnKey, acquireWriteLockOnKey, 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, isReadLockedByCurrentThread, isSearchable, isValueInCache, isWriteLockedByCurrentThread, putAll, recalculateSize, registerCacheExtension, 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, unregisterCacheWriter, waitUntilClusterBulkLoadComplete, waitUntilClusterCoherent
-
-
-
-
Constructor Detail
-
UpdatingSelfPopulatingCache
public UpdatingSelfPopulatingCache(Ehcache cache, UpdatingCacheEntryFactory factory) throws CacheException
Creates a SelfPopulatingCache.- Throws:
CacheException
-
-
Method Detail
-
get
public Element get(java.lang.Object key) throws LockTimeoutException
Looks up an object.If null, it creates it. If not null, it updates it. For performance this method should only be used with
UpdatingCacheEntryFactory'sIt is expected that gets, which update as part of the get, might take considerable time. Access to the cache cannot be blocked while that is happening. This method is therefore not synchronized. Sync's are used for thread safety based on key
- Specified by:
getin interfaceEhcache- Overrides:
getin classSelfPopulatingCache- Parameters:
key-- Returns:
- a value
- Throws:
CacheExceptionLockTimeoutException- if timeout millis is non zero and this method has been unable to acquire a lock in that time- See Also:
Ehcache.isExpired(net.sf.ehcache.Element)
-
update
protected void update(java.lang.Object key)
Element can never be null. Add a null guard just in case.- Parameters:
key-
-
refresh
public void refresh() throws CacheExceptionThis method should not be used. Because elements are always updated before they are returned, it makes no sense to refresh this cache.- Overrides:
refreshin classSelfPopulatingCache- Throws:
CacheException
-
-