public static class CacheHelper { #region 设置缓存容器 //缓存容器 private static Dictionary<string, object> CacheDictionary = new Dictionary<string, object>(); /// <summary> /// 添加缓存 /// </summary> public static void AddCache(string key, object value) { CacheDictionary.Add(key, value); } /// <summary> /// 获取缓存 /// </summary> public static T GetCache<T>(string key) { return (T)CacheDictionary[key]; } /// <summary> /// 判断缓存是否存在 /// </summary> /// <param name="key"></param> /// <returns></returns> public static bool Exsits(string key) { return CacheDictionary.ContainsKey(key); } #endregion }
原文:https://www.cnblogs.com/dot-caohui/p/10968883.html