mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Added in memory caching
This commit is contained in:
27
KfChatDotNetBot/Commands/CacheCommands.cs
Normal file
27
KfChatDotNetBot/Commands/CacheCommands.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user