removeUsers method

Result<CacheEntry<K, V, U>, CachetteError> removeUsers(
  1. K key,
  2. Set<U> users, {
  3. bool removeIfUnused = true,
  4. bool callOnEvict = true,
})

Removes users from thee cache item with key. If removeIfUnused and the item has no users after removing users, it will be removed from the cache.

Implementation

Result<CacheEntry<K, V, U>, CachetteError> removeUsers(
  K key,
  Set<U> users, {
  bool removeIfUnused = true,
  bool callOnEvict = true,
}) {
  if (!_items.containsKey(key)) {
    return Result.error(NotFoundError(key));
  }
  final info = _registry[key]!.removeUsers(users);
  if (info.users.isEmpty && removeIfUnused) {
    return remove(key, callOnEvict: callOnEvict);
  }
  _registry[key] = info;
  return Result.ok(CacheEntry.build(_items[key]!, info));
}