fetch method

Future<T> fetch(
  1. DocumentReference<Object?> ref
)

Fetch data from

  1. Memory
  2. Firebase cache if not available in memory
  3. Firestore server if not available in cache

in the given order for the given ref.

Implementation

Future<T> fetch(DocumentReference ref) async {
  final completer = Completer();
  _fetch(ref, completer);

  final memItem = _items[ref.path];
  if (memItem != null) {
    return memItem;
  }

  final item = await _addon.tryFetch(
    ref: ref,
    source: Source.cache,
  );

  if (item != null) {
    _items[ref.path] = item;
    return item;
  }
  await completer.future;
  return _items[ref.path]!;
}