remember<T> static method

Future<T> remember<T>(
  1. String key,
  2. Duration ttl,
  3. FutureOr<T> callback()
)

Retrieves an item, or stores the result of the callback if it doesn't exist.

Implementation

static Future<T> remember<T>(String key, Duration ttl, FutureOr<T> Function() callback) async {
  final value = await get<T>(key);
  if (value != null) return value;

  final result = await callback();
  await put(key, result, ttl: ttl);
  return result;
}