/// <summary>
    /// 系统缓存
    /// </summary>
    public class Caching
    {
        /// <summary>
        /// 缓存对象
        /// </summary>
        public static readonly Caching Cache = new Caching();
        private System.Collections.Hashtable _cache;

        private Caching()
        {
            _cache = new Hashtable();
        }
        /// <summary>
        /// 获取/设置缓存对象
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns></returns>
        public object this[string key]
        {
            get
            {
                //获取缓存对象
                return (_cache[key]);
            }
            set
            {
                if (_cache.Contains(key))
                {
                    //缓存中已存在该键,先删除该键,然后设置新的键及对象
                    Remove(key);
                }
                //添加缓存对象
                _cache.Add(key, value);
            }
        }
        /// <summary>
        /// 清除缓存中指定键对象
        /// </summary>
        /// <param name="key">键值</param>
        public void Remove(string key)
        {
            _cache.Remove(key);
        }
        /// <summary>
        /// 清除缓存中所有对象
        /// </summary>
        public void RemoveAll()
        {
            _cache.Clear();
        }
    }

相关文章:

  • 2021-04-19
  • 2021-08-15
  • 2021-11-25
  • 2020-07-27
  • 2021-06-21
  • 2021-05-31
猜你喜欢
  • 2022-12-23
  • 2022-03-11
  • 2022-12-23
  • 2021-05-22
  • 2021-06-30
  • 2021-09-16
相关资源
相似解决方案