getOrPut method
V
getOrPut(
- K key,
- V compute()
Returns the value for key. If absent, computes it with compute,
stores it, and returns it.
final cache = <String, int>{};
cache.getOrPut('key', () => expensiveCompute()); // computes once
Implementation
V getOrPut(K key, V Function() compute) {
if (!containsKey(key)) this[key] = compute();
return this[key] as V;
}