namespace PBS.WinFrmUI.Hydro { /// /// 缓存辅助类 /// public class AnalysisParameterCacheHelper { private const string _contentKey = "AnalysisParameterDictKey"; // 查询缓存键 private static string GetCacheKey(long Id) { return CacheKeyHelper.GetCacheKey(_contentKey+ Id); } /// /// 设置缓存 /// public static void Set(long Id,Dictionary> list, int minutes = 30, int randomSeconds = 0) { var cacheKey = GetCacheKey(Id); MemoryCacheHelper.Set(cacheKey, list, minutes * 60 + randomSeconds); } /// /// 查询缓存 /// public static Dictionary> Get(long Id) { var cacheKey = GetCacheKey(Id); return MemoryCacheHelper.Get>>(cacheKey); } /// /// 查询设置缓存 /// public static async Task>> GetSet(long Id, Func>>> func, int minutes = 30, int randomSeconds = 0) { var cacheKey = GetCacheKey(Id); return await MemoryCacheHelper.GetSet(cacheKey, func, minutes * 60 + randomSeconds); } } internal class CacheKeyHelper { private const string _cacheKeyPrefix = "*Default_Basic_Prefix*";//缓存键前缀 /// /// 查询缓存键 /// public static string GetCacheKey(string keyContent) { return string.Format("{0}_{1}", _cacheKeyPrefix, keyContent); } /// /// 清除全部 /// public static void Clear() { MemoryCacheHelper.Remove((key) => { return key.StartsWith(_cacheKeyPrefix); }); } } }