using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.Server { public class RecordCacheHelper { private static Dictionary> _dict = new Dictionary>(); /// /// 设置缓存 /// public static void Set(long CorpID, IEnumerable list) { if (list == null) list = new List(); if (_dict.ContainsKey(CorpID)) { if (_dict[CorpID] == null) { _dict[CorpID] = new List(); } var cache = _dict[CorpID]; list.ToList().ForEach(x => { cache.RemoveAll(t => t.MonitorPointID == x.MonitorPointID && t.SignalID == x.SignalID); cache.Add(x); }); } else { _dict.Add(CorpID, list.ToList()); } } /// /// 获取缓存 /// public static List Get(long CorpID, IEnumerable MonitorPointIds) { if (MonitorPointIds == null || MonitorPointIds.Count() < 1) return default; if (!_dict.ContainsKey(CorpID)) { return default; } if (_dict[CorpID] == null) _dict[CorpID] = new List(); var cache = _dict[CorpID]; return cache.Where(x => MonitorPointIds.Contains(x.MonitorPointID)).ToList(); } } }