Added in memory caching

This commit is contained in:
barelyprofessional
2024-08-17 23:45:29 +08:00
parent b390368713
commit 71b46d73d2
10 changed files with 428 additions and 70 deletions

View File

@@ -0,0 +1,27 @@
using System.Runtime.Caching;
using System.Text.RegularExpressions;
using KfChatDotNetBot.Models.DbModels;
using KfChatDotNetWsClient.Models.Events;
namespace KfChatDotNetBot.Commands;
public class CacheClearCommand : ICommand
{
public List<Regex> Patterns => [
new Regex("^cache clear")
];
public string HelpText => "Clear the cache";
public bool HideFromHelp => true;
public UserRight RequiredRight => UserRight.Admin;
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
{
var cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList();
foreach (var cacheKey in cacheKeys)
{
MemoryCache.Default.Remove(cacheKey);
}
botInstance.SendChatMessage("Cache wiped", true);
}
}