ehcache

net.sf.ehcache.constructs.blocking
Class UpdatingSelfPopulatingCache

java.lang.Object
  extended by net.sf.ehcache.constructs.EhcacheDecoratorAdapter
      extended by net.sf.ehcache.constructs.blocking.BlockingCache
          extended by net.sf.ehcache.constructs.blocking.SelfPopulatingCache
              extended by net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache
All Implemented Interfaces:
Cloneable, Ehcache, InternalEhcache

public class UpdatingSelfPopulatingCache
extends SelfPopulatingCache

A Cache backed 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: UpdatingSelfPopulatingCache.java 5594 2012-05-07 16:04:31Z cdennis $
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
UpdatingSelfPopulatingCache(Ehcache cache, UpdatingCacheEntryFactory factory)
          Creates a SelfPopulatingCache.
 
Method Summary
 Element get(Object key)
          Looks up an object.
 void refresh()
          This method should not be used.
protected  void update(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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UpdatingSelfPopulatingCache

public UpdatingSelfPopulatingCache(Ehcache cache,
                                   UpdatingCacheEntryFactory factory)
                            throws CacheException
Creates a SelfPopulatingCache.

Throws:
CacheException
Method Detail

get

public Element get(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's

It 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:
get in interface Ehcache
Overrides:
get in class SelfPopulatingCache
Parameters:
key -
Returns:
a value
Throws:
CacheException
LockTimeoutException - 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(Object key)
Element can never be null. Add a null guard just in case.

Parameters:
key -

refresh

public void refresh()
             throws CacheException
This method should not be used. Because elements are always updated before they are returned, it makes no sense to refresh this cache.

Overrides:
refresh in class SelfPopulatingCache
Throws:
CacheException

ehcache

Copyright 2001-2014, Terracotta, Inc.