Retrieves a value from a cache given a key. The compiler provides special
consideration for this call such that it is generally considered side-effect
free. However, if the opt_keyFn
or valueFn
have side-effects
then the entire call is considered to have side-effects.
Conventionally storing the value on the cache would be considered a
side-effect and preclude unused calls from being pruned, ie. even if
the value was never used, it would still always be stored in the cache.
Providing a side-effect free valueFn
and opt_keyFn
allows unused calls to goog.reflect.cache
to be pruned.
Parameters | cacheObj | Object<(K|null), (V|null)> | | The object that contains the cached values.
| key | ? | | The key to lookup in the cache. If it is not string or number
then a opt_keyFn should be provided. The key is also used as the
parameter to the valueFn .
| valueFn | function(?): (V|null) | | The value provider to use to calculate the
value to store in the cache. This function should be side-effect free
to take advantage of the optimization.
| opt_keyFn | function(?): (K|null)= | | The key provider to determine the cache
map key. This should be used if the given key is not a string or number.
If not provided then the given key is used. This function should be
side-effect free to take advantage of the optimization.
|
|
---|
Returns | V | The cached or calculated value.
|
|
---|