ReloadableCache Interface

com.bea.p13n.cache
ReloadableCache Interface

public interface ReloadableCache

A cache that supports adding entries that know how to reload (rebuild) themselves. The CacheReloader is only used to rebuild the entry when it expires, and does not take effect when the entry is removed for other reasons (such as administrative flush, or if the entry is removed because the Cache's MaxEntries is hit).

Related Topics

Cache
CacheReloader


All Known Subinterfaces

Cache

Method Summary

public CacheReloader
getReloader(Object key)
Get the CacheReloader in effect for the given key, or null if no reloader is set.
public Object
put(Object key, Object val, CacheReloader reloader)
Put a value into the cache and set a CacheReloader to rebuild the value when it expires.
public Object
put(Object key, Object val, long ttl, CacheReloader reloader)
Put a value into the cache, with a specific time-to-live, and a CacheReloader used to rebuild the value when that time-to-live expires.
public void
reload(Object key)
Run the reloader explicitly to refresh the value in the cache.
public void
setReloader(Object key, CacheReloader reloader)
Set reloader to be run when the cached object has expired.
public CacheReloader
unsetReloader(Object key)
Remove the reloader.

Method Detail

getReloader(Object) Method

public CacheReloader getReloader(Object key)
Get the CacheReloader in effect for the given key, or null if no reloader is set.

Parameters

key
the key to query

Returns

the CacheReloader for that key

put(Object, Object, CacheReloader) Method

public Object put(Object key, 
                  Object val, 
                  CacheReloader reloader)
Put a value into the cache and set a CacheReloader to rebuild the value when it expires.

Neither the key nor the value can be null. The reloader may be null (in which case no reloader is used and the value will expire in the "normal" way.

Parameters

key
the key of the entry to create
val
the value to associate with the key
reloader
the CacheReloader to use when the entry expires

Returns

Object the previous value for the key

put(Object, Object, long, CacheReloader) Method

public Object put(Object key, 
                  Object val, 
                  long ttl, 
                  CacheReloader reloader)
Put a value into the cache, with a specific time-to-live, and a CacheReloader used to rebuild the value when that time-to-live expires.

Neither the key nor the value can be null. The reloader may be null (in which case no reloader is used and the value will expire in the "normal" way.

Note that it does not make sense to set a reloader and set the ttl to Cache.TTL_NEVER_EXPIRE, since the reloader will never be called in this case (but there is no restriction enforced against doing that).

Parameters

key
the key of the entry to create
val
the value to associate with the key
ttl
time-to-live, in milliseconds, of the object. This ttl overrides the default ttl for the cache, and applies only to this object.

Returns

Object the previous value for the key

reload(Object) Method

public void reload(Object key)
Run the reloader explicitly to refresh the value in the cache. This method blocks until the object is reloaded.

Parameters

key
the key to be refreshed by the reloaders

setReloader(Object, CacheReloader) Method

public void setReloader(Object key, 
                        CacheReloader reloader)
Set reloader to be run when the cached object has expired. When someone calls get() for this key and the entry has expired, the reloader is run to rebuild the object and refresh the cache rahter than the normal behavior of removing the expired entry (and get returning null). Cached objects without a reloader behave "normally".

Parameters

key
the cache key to add (or replace) the reloader
reloader
the CacheReloader (or null to remove/unset the reloader for this key

unsetReloader(Object) Method

public CacheReloader unsetReloader(Object key)
Remove the reloader. Reloaders can also be removed by calling setReloader(key,null). Reloaders are also removed when the cache entry is removed using remove(key).

Parameters

key
the key for which the reloader is to be removed

Returns

the removed (previous) reloader (or null if none was set)