private async Task CmdCacheClear(CommandContext context, CancellationToken cancellationToken = default) { // flush all batches first to prevent data loss _groupConfigStore.FlushBatch(); _idQueueStore.FlushBatch(); _userDataStore.FlushBatch(); // get current counts for reporting int userDataCacheCount = _userDataCache.CachedCount; int groupConfigCacheCount = _groupConfigCache.CachedCount; int idQueueCacheCount = _idQueueCache.CachedCount; int mentionConfigCacheCount = _mentionConfigCache.CachedCount; // clear caches _userDataCache.Clear(); _groupConfigCache.Clear(); _idQueueCache.Clear(); _mentionConfigCache.Clear(); // reply to user await context.ReplyTextAsync("(y) Database caches cleared:\r\n" + $"{nameof(IUserDataCache)}: {userDataCacheCount}\r\n" + $"{nameof(IGroupConfigCache)}: {groupConfigCacheCount}\r\n" + $"{nameof(IIdQueueCache)}: {idQueueCacheCount}\r\n" + $"{nameof(IMentionConfigCache)}: {mentionConfigCacheCount}", cancellationToken).ConfigureAwait(false); // log the change WolfUser user = await context.Client.GetUserAsync(context.Message.SenderID.Value, cancellationToken).ConfigureAwait(false); using IDisposable clearedLogScope = _log.BeginScope(new Dictionary <string, object>() { { "UserDataCacheCount", userDataCacheCount }, { "GroupConfigCacheCount", groupConfigCacheCount }, { "IdQueueCacheCount", idQueueCacheCount }, { "MentionConfigCacheCount", mentionConfigCacheCount } }); _log.LogInformation("All database caches cleared by {UserID} ({UserNickname})", user.ID, user.Nickname); }