/**
* Cache to use.
*/
- private Cache<KeyType, ValueType> _cache;
+ private Cache<KeyType, ValueType> cache;
/**
* Key of the object in the cache.
*/
- private KeyType _objectKey;
+ private KeyType objectKey;
/**
* Computation used to obtain the object if it is not found in the cache.
*/
- private Computation<KeyType, ValueType> _computation;
+ private Computation<KeyType, ValueType> computation;
/**
* Constructs the cached object.
*/
public CachedObject(Cache<KeyType, ValueType> aCache, KeyType aObjectKey,
Computation<KeyType, ValueType> aComputation) {
- _cache = aCache;
- _objectKey = aObjectKey;
- _computation = aComputation;
+ cache = aCache;
+ objectKey = aObjectKey;
+ computation = aComputation;
}
/**
* @return Object.
*/
public ValueType get() {
- ValueType object = (ValueType) _cache.get(_objectKey); // the used
+ ValueType object = (ValueType) cache.get(objectKey); // the used
// cache is
// thread safe.
if (object == null) {
// be
// recomputed.
synchronized (this) {
- object = (ValueType) _cache.get(_objectKey);
+ object = (ValueType) cache.get(objectKey);
if (object == null) {
// No other thread did a recomputation so we must do this
// now.
- LOGGER.debug("Refreshing cache for '" + _objectKey + "'");
- object = _computation.getObject(_objectKey);
- _cache.put(_objectKey, object);
+ LOGGER.debug("Refreshing cache for '" + objectKey + "'");
+ object = computation.getObject(objectKey);
+ cache.put(objectKey, object);
}
}
}
*
*/
public void invalidate() {
- _cache.remove(_objectKey);
+ cache.remove(objectKey);
}
/**
* @return Cache.
*/
public Cache getCache() {
- return _cache;
+ return cache;
}
}