delete method

Future<void> delete()

Deletes from local cache. Non-local collections sync the deletion.

Implementation

Future<void> delete() async {
  // Clear pending tags on delete
  _onMutate?.call();
  final smart = _smartCache;

  // Local collections only evict from cache
  if (_local) {
    if (smart != null) {
      await smart.evict(_blockId);
    } else {
      await _cache?.evict(_blockId);
    }
    return;
  }

  if (!_ws.isConnected && smart != null) {
    await smart.evict(_blockId);
    await smart.enqueueDelete(_blockId);
    return;
  }

  try {
    await _ws.delete(_blockId);
    _ws.emitLocalSync(SyncEvent(action: 'delete', blockId: _blockId));
  } catch (e) {
    if (e is WsDeniedException) rethrow;
    if (smart != null) {
      await smart.evict(_blockId);
      await smart.enqueueDelete(_blockId);
      return;
    }
    rethrow;
  }
  if (smart != null) {
    await smart.evict(_blockId);
  } else {
    final cache = _effectiveCache;
    if (cache != null) { await cache.evict(_blockId); }
  }
}