onSubscription method

  1. @override
Future<void> onSubscription(
  1. Request request,
  2. Snapshot snapshot
)

Implementation

@override
Future<void> onSubscription(Request request, Snapshot snapshot) async {
  final String key = _generateKey(request);

  final containsCache = await _storage.containsKey(key);
  if (containsCache) {
    final cachedData = await _storage.get(key);
    snapshot.add(cachedData);
  }
  final subscription = snapshot.listen((data) => _updateSubscriptionCache(key, data));
  snapshot.listen((_) {}, onDone: () => subscription.cancel());
}