putIfAbsent method

V putIfAbsent(
  1. K key,
  2. V ifAbsent()
)

Insert via ifAbsent only when key is absent (or expired). An explicitly cached null value counts as present.

Implementation

V putIfAbsent(K key, V Function() ifAbsent) {
  if (contains(key)) {
    return get(key) as V;
  }
  final value = ifAbsent();
  set(key, value);
  return value;
}