release method

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

Marks a TIdentifier TValue pair as eligible for removal.

The decision of whether or not to actually remove the value will be up to the current CachingStrategy.

Release indicates that consuming code has finished with the TIdentifier TValue pair associated with id. This pair may be removed immediately or in time depending on the CachingStrategy. Access to the pair will be blocked immediately, i.e. the liveValues getter won't report this item, even if the pair isn't immediately removed from the cache. A get or getAsync must be performed to mark the item as ineligible for removal and live in the cache again.

If the Cache isOrWillBeDisposed then a StateError is thrown.

Implementation

@mustCallSuper
Future<Null> release(TIdentifier id) {
  _log.finest('release id: $id');
  _throwWhenDisposed('release');
  _isReleased[id] = true;
  // Await any pending cached futures
  if (_cache.containsKey(id)) {
    _cachingStrategy.onWillRelease(id);
    return _cache[id]!.then((TValue value) async {
      await _cachingStrategy.onDidRelease(id, value, remove);
      _didReleaseController.add(CacheContext(id, value));
    }).catchError((Object error, StackTrace stackTrace) {
      return null;
    });
  }

  return Future.value();
}