You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
902 B

using System.Collections.Concurrent;
namespace HybirdFrameworkDriver.Common;
public class MsgCache
{
private readonly ConcurrentDictionary<string, dynamic> _dictionary = new();
private static readonly string MsgKey = "msg_";
public void Add(string key, dynamic value)
{
_dictionary[key] = value;
}
public bool TryGet(string key, out dynamic? value)
{
return _dictionary.TryGetValue(key, out value);
}
public void Remove(string key)
{
_dictionary.Remove(key, out var value);
}
public void AddByMsgId(int key, dynamic value)
{
_dictionary[MsgKey + key] = value;
}
public bool TryGetMsgId(int key, out dynamic? value)
{
return _dictionary.TryGetValue(MsgKey + key, out value);
}
public void RemoveMsgId(int key)
{
_dictionary.Remove(MsgKey + key, out var value);
}
}