现数据库内有信息百万条,我希望客户端每次登陆后,信息都存在缓存中,是否可行(winform)

解决方案 »

  1.   

    写一个缓存类存取namespace HZ
    {
        using System.Collections.Generic;    /**//// <summary>
        /// 全局统一的缓存类
        /// </summary>
        public class Cache
        {
            private SortedDictionary<string, string> dic = new SortedDictionary<string, string>();
            private static volatile Cache instance = null;
            private static object lockHelper = new object();        private Cache()
            {        }
            public void Add(string key, string value)
            {
                dic.Add(key, value);
            }
            public void Remove(string key)
            {
                dic.Remove(key);
            }        public string this[string index]
            {
                get
                {
                    if (dic.ContainsKey(index))
                        return dic[index];
                    else
                        return null;
                }
                set { dic[index] = value; }
            }        public static Cache Instance
            {
                get
                {
                    if (instance == null)
                    {
                        lock (lockHelper)
                        {
                            if (instance == null)
                            {
                                instance = new Cache();
                            }
                        }
                    }
                    return instance;
                }
            }
        }
    }