Package org.faktorips.runtime.caching
Class HardMemoizer<A,V>
java.lang.Object
org.faktorips.runtime.caching.HardMemoizer<A,V>
- All Implemented Interfaces:
IComputable<A,V>
This memoizer is implemented as suggested by Brian Goetz in Java Concurrency in Practice. It is a
thread safe caching mechanism that loads not stored objects by calling an
IComputable.
It is called "hard" to differentiate it from the previous Memoizer using
SoftReferences.-
Method Summary
Modifier and TypeMethodDescriptionCompute an object of type V identified by the key of type KGetting theClassof the value this computable produces.static <K,V> HardMemoizer<K, V> Creates a newHardMemoizerfor the given value class using the givenFunctionto compute the values from keys.static <K,V> HardMemoizer<K, V> of(IComputable<K, V> computable) Creates a newHardMemoizerfor the given value class using the givenIComputableto compute the values from keys.
-
Method Details
-
of
Creates a newHardMemoizerfor the given value class using the givenIComputableto compute the values from keys.- Type Parameters:
K- the key typeV- the value type- Parameters:
computable- the function to compute a value from a key- Returns:
- a new
IComputablethat includes caching
-
of
Creates a newHardMemoizerfor the given value class using the givenFunctionto compute the values from keys.- Type Parameters:
K- the key typeV- the value type- Parameters:
valueClass- the class of the valuesfunction- the function to compute a value from a key- Returns:
- a new
IComputablethat includes caching
-
getValueClass
Description copied from interface:IComputableGetting theClassof the value this computable produces.- Specified by:
getValueClassin interfaceIComputable<A,V>
-
compute
Description copied from interface:IComputableCompute an object of type V identified by the key of type K- Specified by:
computein interfaceIComputable<A,V> - Parameters:
arg- the key to identify the object- Returns:
- the computed Object of type V
- Throws:
InterruptedException- When computation was interrupted
-