remove method

  1. @mustCallSuper
Future<Null> remove(
  1. TIdentifier id
)

Removes the reference to a TValue associated with the given TIdentifier.

A CacheContext value is emitted by the didUpdate stream upon successful removal of the given TIdentifier. In addition, a CacheContext value is emitted by the didRemove stream upon successful removal from the cache.

If the Cache isOrWillBeDisposed then a StateError is thrown.

Implementation

@mustCallSuper
Future<Null> remove(TIdentifier id) {
  _log.finest('remove id: $id');
  _throwWhenDisposed('remove');
  _isReleased.remove(id);
  if (_cache.containsKey(id)) {
    _cachingStrategy.onWillRemove(id);
    final removedValue = _cache.remove(id);
    if (removedValue != null) {
      return removedValue.then((TValue value) async {
        if (_applyToItemCallBacks[id] != null) {
          await Future.wait(_applyToItemCallBacks[id]!);
        }
        await _cachingStrategy.onDidRemove(id, value);
        _didRemoveController.add(CacheContext(id, value));
        _didUpdateController.add(CacheContext(id, null));
      }).catchError((Object error, StackTrace stackTrace) {
        return null;
      });
    }
  }

  return Future.value();
}