using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.BLL { /// /// MonitorPoint缓存辅助类 /// internal class MonitorPointCacheHelper { private const string _contentKey = "MonitorPointListKey"; private static string GetCacheKey(long projectId) { var contentKey = string.Format("{0}-{1}", _contentKey, projectId); return CacheHelper.GetCacheKey(contentKey); } /// /// 设置缓存 /// public static void Set(long projectId, List list, int Minites = 30, int RandomSeconds = 0) { var cacheKey = GetCacheKey(projectId); MemoryCacheHelper.Set(cacheKey, list, Minites * 60 + RandomSeconds); } /// /// 获取缓存 /// public static List Get(long projectId) { var cacheKey = GetCacheKey(projectId); return MemoryCacheHelper.Get>(cacheKey); } /// /// 获取设置缓存 /// public static List GetSet(long projectId, Func> func, int Minites = 30, int RandomSeconds = 0) { var cacheKey = GetCacheKey(projectId); return MemoryCacheHelper.GetSet(cacheKey, func, Minites * 60 + RandomSeconds); } /// /// 移除缓存 /// public static void Remove(long projectId) { var cacheKey = GetCacheKey(projectId); MemoryCacheHelper.Remove(cacheKey); } /// /// 全部移除 /// public static void RemoveAll() { MemoryCacheHelper.Remove((key) => { return key.Contains(CacheHelper.GetCacheKey(_contentKey)); }); } } }