flexible<T> method

Future<T> flexible<T>(
  1. String key,
  2. Duration fresh,
  3. Duration stale,
  4. FutureOr<T> compute(), {
  5. T decode(
    1. Object? json
    )?,
})

Stale while revalidate. For fresh the value is served as it is. After that, until fresh + stale, the old value is still served at once, and one caller runs compute in the background.

await Cache().flexible('stats', Duration(minutes: 1),
    Duration(minutes: 5), () => loadStats());

Implementation

Future<T> flexible<T>(
  String key,
  Duration fresh,
  Duration stale,
  FutureOr<T> Function() compute, {
  T Function(Object? json)? decode,
}) {
  return repository.flexible<T>(key, fresh, stale, compute, decode: decode);
}