A variation on
CachedValue
which allows to reuse the same value provider in all cached values, make it static
and thus save some memory.
In most cases
CachedValue
should be preferred:
the memory benefits of parameterization are negligible, while the client code becomes longer, more complicated and error-prone.
Note that this object holds just one cached value, not a map from parameters to their respective results.
So the
value
argument of
getValue(Object)
method must always be the same
for the same
ParameterizedCachedValue
(most likely it'll be the object where this
ParameterizedCachedValue
is stored as a field or user data). Otherwise the cache would contain some accidental data
depending on which thread called it first with which argument.