initializeCache<T> method

T initializeCache<T>(
  1. String key,
  2. T value
)

Initializes the cache if it has not been initialized and returns the initial value or an already existing value.

Implementation

T initializeCache<T>(String key, T value) {
  final result = cache[key];
  if (result is T) {
    return result;
  }

  cache[key] = value;
  return value;
}