using ProtoBuf; using Server.Configs; using Server.MyClass.Class; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Server.MyClass.Caches { [ProtoContract] public class RuntimeCache { [global::ProtoBuf.ProtoMember(1)] public List TbDatas { get; set; } /// /// 抖音同步相关信息 /// [global::ProtoBuf.ProtoMember(2)] public List DyDatas { get; set; } [global::ProtoBuf.ProtoMember(3)] public List MtDatas { get; set; } /// /// 京东 /// [global::ProtoBuf.ProtoMember(4)] public List JDDatas { get; set; } /// /// 拼多多 /// [global::ProtoBuf.ProtoMember(5)] public List PDDDatas { get; set; } /// /// 唯品会 /// [global::ProtoBuf.ProtoMember(6)] public List WeiPinHuiDatas { get; set; } /// /// 苏宁 /// [global::ProtoBuf.ProtoMember(7)] public List SuningDatas { get; set; } /// /// 公共数据缓存配置 /// [global::ProtoBuf.ProtoMember(8)] public Dictionary PublicCacheDic { get; set; } [global::ProtoBuf.ProtoMember(9)] public ConcurrentDictionary DeviceSessions { get; set; } public ConcurrentDictionary UserSessions { get; set; } /// /// 用来缓存存储公共配置 /// /// /// /// public bool SetPublicValue(string key, T value) { PublicCacheDic[key] = Newtonsoft.Json.JsonConvert.SerializeObject(value); return true; } /// /// 获取 用来缓存存储公共配置 /// /// /// /// public T GetPublicValue(string key, Func def = null) { if (PublicCacheDic.ContainsKey(key)) { var val = PublicCacheDic[key]; var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(val); return (T)Convert.ChangeType(obj, typeof(T)); } if (def == null) { return default; } return def(); } public RuntimeCache() { PublicCacheDic = new Dictionary(); TbDatas = new List(); DyDatas = new List(); MtDatas = new List(); JDDatas = new List(); PDDDatas = new List(); WeiPinHuiDatas = new List(); SuningDatas = new List(); DeviceSessions = new ConcurrentDictionary(); UserSessions = new ConcurrentDictionary(); } } }