get method

Future<V> get(
  1. K key
)

Gets the value for the given key from the cache or uses the provider set in the constructor to calculate (and store) the value.

Can only be used if provider is set, if not set, this will throw an exception

Implementation

Future<V> get(K key) {
  if (provider == null) {
    throw ArgumentError(
      '[] and get can only be used if a provider is set in the constructor',
    );
  }
  return _cache
      .putIfAbsent(
          key,
          () => SingleValueCache(
              maxAge: maxAge, provider: () => provider!(key)))
      .value;
}