yz_server/Server/MyClass/Caches/RuntimeCache.cs

108 lines
3.5 KiB
C#
Raw Normal View History

2022-04-16 07:48:12 +00:00
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<TaobaoUpdateCacheInfo> TbDatas { get; set; }
/// <summary>
/// 抖音同步相关信息
/// </summary>
[global::ProtoBuf.ProtoMember(2)]
public List<DouyinUpdateCache> DyDatas { get; set; }
[global::ProtoBuf.ProtoMember(3)]
public List<MtUpdateOrderItemCache> MtDatas { get; set; }
/// <summary>
/// 京东
/// </summary>
[global::ProtoBuf.ProtoMember(4)]
public List<JDUpdateOrderItemCache> JDDatas { get; set; }
/// <summary>
/// 拼多多
/// </summary>
[global::ProtoBuf.ProtoMember(5)]
public List<PDDUpdateOrderItemCache> PDDDatas { get; set; }
/// <summary>
/// 唯品会
/// </summary>
[global::ProtoBuf.ProtoMember(6)]
public List<WeiPinHuiUpdateOrderItemCache> WeiPinHuiDatas { get; set; }
/// <summary>
/// 苏宁
/// </summary>
[global::ProtoBuf.ProtoMember(7)]
public List<SuningUpdateOrderItemCache> SuningDatas { get; set; }
/// <summary>
/// 公共数据缓存配置
/// </summary>
[global::ProtoBuf.ProtoMember(8)]
public Dictionary<string, string> PublicCacheDic { get; set; }
[global::ProtoBuf.ProtoMember(9)]
public ConcurrentDictionary<string, DeviceSession> DeviceSessions { get; set; }
public ConcurrentDictionary<int, UserSession> UserSessions { get; set; }
/// <summary>
/// 用来缓存存储公共配置
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool SetPublicValue<T>(string key, T value)
{
PublicCacheDic[key] = Newtonsoft.Json.JsonConvert.SerializeObject(value);
return true;
}
/// <summary>
/// 获取 用来缓存存储公共配置
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public T GetPublicValue<T>(string key, Func<T> def = null)
{
if (PublicCacheDic.ContainsKey(key))
{
var val = PublicCacheDic[key];
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(val);
return (T)Convert.ChangeType(obj, typeof(T));
}
if (def == null)
{
return default;
}
return def();
}
public RuntimeCache()
{
PublicCacheDic = new Dictionary<string, string>();
TbDatas = new List<TaobaoUpdateCacheInfo>();
DyDatas = new List<DouyinUpdateCache>();
MtDatas = new List<MtUpdateOrderItemCache>();
JDDatas = new List<JDUpdateOrderItemCache>();
PDDDatas = new List<PDDUpdateOrderItemCache>();
WeiPinHuiDatas = new List<WeiPinHuiUpdateOrderItemCache>();
SuningDatas = new List<SuningUpdateOrderItemCache>();
DeviceSessions = new ConcurrentDictionary<string, DeviceSession>();
UserSessions = new ConcurrentDictionary<int, UserSession>();
}
}
}