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

public Class UpdatingSelfPopulatingCache

extends SelfPopulatingCache
Class Inheritance
Imports
net.sf.ehcache.CacheException, .Ehcache, .Element, net.sf.ehcache.concurrent.Sync, .LockType, org.slf4j.Logger, .LoggerFactory

A net.sf.ehcache.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.

Author
Greg Luck
Version
$Id: UpdatingSelfPopulatingCache.java 10789 2018-04-26 02:08:13Z adahanne $

Field Summary

Modifier and TypeField and Description
private static final Logger
Inherited from net.sf.ehcache.constructs.blocking.SelfPopulatingCache:
factory

Constructor Summary

AccessConstructor and Description
public
UpdatingSelfPopulatingCache(Ehcache cache, final UpdatingCacheEntryFactory factory)

Creates a SelfPopulatingCache.

Method Summary

Modifier and TypeMethod and Description
public Element

Returns:

a value
get
(final Object key)

Overrides net.sf.ehcache.constructs.blocking.SelfPopulatingCache.get.

Implements net.sf.ehcache.Ehcache.get.

Looks up an object.
public void
refresh()

Overrides net.sf.ehcache.constructs.blocking.SelfPopulatingCache.refresh.

This method should not be used.
protected void
update(final Object key)

Element can never be null.

Inherited from net.sf.ehcache.constructs.blocking.SelfPopulatingCache:
makeAndCheckElementrefreshrefreshrefreshrefreshElementrefreshElement

Field Detail

LOGback to summary
private static final Logger LOG

Hides net.sf.ehcache.constructs.blocking.SelfPopulatingCache.LOG.

Constructor Detail

UpdatingSelfPopulatingCacheback to summary
public UpdatingSelfPopulatingCache(Ehcache cache, final UpdatingCacheEntryFactory factory) throws CacheException

Creates a SelfPopulatingCache.

Method Detail

getback to summary
public Element get(final Object key) throws LockTimeoutException

Overrides net.sf.ehcache.constructs.blocking.SelfPopulatingCache.get.

Implements net.sf.ehcache.Ehcache.get.

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

Returns:Element

a value

Exceptions
LockTimeoutException:

Doc from net.sf.ehcache.constructs.blocking.BlockingCache.get.

if timeout millis is non zero and this method has been unable to acquire a lock in that time

refreshback to summary
public void refresh() throws CacheException

Overrides net.sf.ehcache.constructs.blocking.SelfPopulatingCache.refresh.

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

updateback to summary
protected void update(final Object key)

Element can never be null. Add a null guard just in case.