缓存帮助类CacheHelper

public class CacheHelper
    {
        //缓存容器 
        private static Dictionary<string, object> CacheDictionary = new Dictionary<string, object>();
        /// <summary>
        /// 添加缓存
        /// </summary>
        public static void Add(string key, object value)
        {
            CacheDictionary.Add(key, value);
        }

        /// <summary>
        /// 获取缓存
        /// </summary>
        public static T Get<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);
        }
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static bool Remove(string key)
        {
            return CacheDictionary.Remove(key);
        }
        /// <summary>
        /// 更新缓存
        /// </summary>
        public static void Update(string key, object value)
        {
            CacheDictionary.Remove(key);
            CacheDictionary.Add(key, value);
        }
    }

 

posted @ 2019-08-01 15:32  SmilePastaLi  阅读(309)  评论(0编辑  收藏  举报