org.wamblee.cache
Class CachedObject<KeyType extends java.io.Serializable,ValueType extends java.io.Serializable>

java.lang.Object
  extended by org.wamblee.cache.CachedObject<KeyType,ValueType>

public class CachedObject<KeyType extends java.io.Serializable,ValueType extends java.io.Serializable>
extends java.lang.Object

Represents a cached object. The object is either retrieved from the cache if the cache has it, or a call back is invoked to get the object (and put it in the cache).

Author:
Erik Brakkee

Nested Class Summary
static interface CachedObject.Computation<Key extends java.io.Serializable,Value extends java.io.Serializable>
          Callback invoked to compute an object if it was not found in the cache.
 
Constructor Summary
CachedObject(Cache<KeyType,ValueType> aCache, KeyType aObjectKey, CachedObject.Computation<KeyType,ValueType> aComputation)
          Constructs the cached object.
 
Method Summary
 ValueType get()
          Gets the object.
 Cache getCache()
          Gets the cache.
 void invalidate()
          Invalidates the cache for the object so that it is recomputed the next time it is requested.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedObject

public CachedObject(Cache<KeyType,ValueType> aCache,
                    KeyType aObjectKey,
                    CachedObject.Computation<KeyType,ValueType> aComputation)
Constructs the cached object.

Parameters:
aCache - Cache to use.
aObjectKey - Key of the object in the cache.
aComputation - Computation to get the object in case the object is not in the cache.
Method Detail

get

public ValueType get()
Gets the object. Since the object is cached, different calls to this method may return different objects.

Returns:
Object.

invalidate

public void invalidate()
Invalidates the cache for the object so that it is recomputed the next time it is requested.


getCache

public Cache getCache()
Gets the cache.

Returns:
Cache.


Copyright © 2010. All Rights Reserved.