net.sf.ehcache.constructs.blocking

Class UpdatingSelfPopulatingCache

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 191 2006-09-03 22:41:48Z gregluck $

Author: Greg Luck

Constructor Summary
UpdatingSelfPopulatingCache(Ehcache cache, UpdatingCacheEntryFactory factory)
Creates a SelfPopulatingCache.
Method Summary
Elementget(Object key)
Looks up an object.
voidrefresh()
This method should not be used.

Constructor Detail

UpdatingSelfPopulatingCache

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

Method Detail

get

public Element get(Object key)
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. Mutexes are used for thread safety based on key

Parameters: key

Returns: a value

Throws: net.sf.ehcache.CacheException

refresh

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