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
Method Summary |
public |
|
public |
|
public |
|
public void | |
public void |
|
public |
|
Method Detail |
publicGet the CacheReloader in effect for the given key, or null if no reloader is set.CacheReloader
getReloader(Object
key)
publicPut a value into the cache and set a CacheReloader to rebuild the value when it expires.Object
put(Object
key,Object
val,CacheReloader
reloader)
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.
Object
the previous value for the key publicPut 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.Object
put(Object
key,Object
val, long ttl,CacheReloader
reloader)
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).
Object
the previous value for the key
public void reload(Object
key)
Run the reloader explicitly to refresh the value in the cache.
This method blocks until the object is reloaded.
public void setReloader(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".Object
key,CacheReloader
reloader)
publicRemove 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).CacheReloader
unsetReloader(Object
key)