public abstract class CachingReference<E> extends Object
Object that it holds and handle the renewal of this object upon expiration.
Greatly inspired by the CachedData sample provided in the javadoc
of ReentrantReadWriteLock.
Object is created implementing the newObject() method.
Sample to get an InetAddress refreshed against a DNS every 10 seconds:
CachingReference myRemoteServerAddress = new CachingReference(10, TimeUnit.SECONDS) {
protected InetAddress newObject() {
try {
return InetAddress.getByName(myRemoteServerHostname);
} catch () {
throw new RuntimeException("Exception resolving '" + myRemoteServerHostname + "'", e);
}
}
}
| Constructor and Description |
|---|
CachingReference(long timeToLiveInNanos) |
CachingReference(long timeToLive,
TimeUnit timeToLiveUnit) |
public CachingReference(long timeToLiveInNanos)
public CachingReference(long timeToLive,
TimeUnit timeToLiveUnit)
Copyright © 2014. All rights reserved.