/// <inheritdoc /> public async Task TrimStream(IStream stream, int version) { var maxVersion = stream.Version; var count = maxVersion - version; Log.StopWatch.Start("TrimStream.TruncateStreamStore"); await TruncateStreamStore(stream, version); Log.StopWatch.Stop("TrimStream.TruncateStreamStore"); if (_useVersionCache) { var dict = _versions.GetOrAdd(stream.Key, new ConcurrentDictionary <int, Time>()); while (maxVersion > version) { dict.TryRemove(maxVersion, out _); maxVersion--; } } Log.Debug($"Deleted ({version + 1}..{maxVersion}) {(count > 1 ? "events" : "event")} from {stream.Key}@{stream.Version}"); stream.Version = version; stream.AddDeleted(count); UpdateStreamMetadata(stream); }