Class FutureCache<K,V,C>
- java.lang.Object
-
- org.exoplatform.commons.notification.impl.service.storage.cache.FutureCache<K,V,C>
-
- Type Parameters:
K- the key type parameterV- the value type parameterC- the context type parameter
- Direct Known Subclasses:
FutureExoCache
public abstract class FutureCache<K,V,C> extends Object
A future cache that prevents the loading of the same resource twice. This should be used when the resource to load is very expensive or cannot be concurrently retrieved (like a classloading).
The future cache should be used with the
get(Object, Object)method, that retrieves an object from the cache. When the object is not found, then theLoader.retrieve(Object, Object)method is used to retrieve the data and then this data is inserted in the cache.The class is abstract and does not implement a cache technology by itself, the cache implementation is delegated to the contractual methods
get(Object)andput(Object, Object). Those methods are intended to be used by the future cache only.The
Loaderinterface provides a source to retrieve objects to put in the cache. The goal to maintain this interface is to decouple the cache from the object source.- Version:
- $Revision$
- Author:
- Julien Viet
-
-
Constructor Summary
Constructors Constructor Description FutureCache(org.exoplatform.commons.cache.future.Loader<K,V,C> loader)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Vget(C context, K key)Perform a cache lookup for the specified key within the specified context.protected abstract Vget(K key)Retrieves the cached value corresponding to the specified key from the cache, it must returns null when the key does not exist.protected abstract voidput(K key, V value)Updates the cache with a new key/value pair.protected abstract voidputOnly(K key, V value)Updates the cache only local mode with a new key/value pair.
-
-
-
Method Detail
-
get
protected abstract V get(K key)
Retrieves the cached value corresponding to the specified key from the cache, it must returns null when the key does not exist. This method is intended for internal use by the future cache only.- Parameters:
key- the key- Returns:
- the cache value
-
put
protected abstract void put(K key, V value)
Updates the cache with a new key/value pair. This method is intended for internal use by the future cache only.- Parameters:
key- the keyvalue- the cache value
-
putOnly
protected abstract void putOnly(K key, V value)
Updates the cache only local mode with a new key/value pair. This method is intended for internal use by the future cache only.- Parameters:
key- the keyvalue- the cache value
-
get
public final V get(C context, K key)
Perform a cache lookup for the specified key within the specified context. When the value cannot be loaded (because it does not exist or it failed or anything else that does not come to my mind), the value null is returned.- Parameters:
context- the context in which the resource is accessedkey- the key identifying the resource- Returns:
- the value
-
-