示例#1
0
        public void TestMCache()
        {
            var obj = MCache.Get("mcache");

            Assert.IsNull(obj);

            MCache.Add("mcache", "MCache1", 10);
            obj = MCache.Get("mcache");
            Assert.AreEqual(obj, "MCache1");

            MCache.Set("mcache", "MCache2", 10);
            obj = MCache.Get("mcache");
            Assert.AreNotEqual(obj, "MCache1");

            MCache.Add("mcache1", "MCache3", 10);
            obj = MCache.Get("mcache1");
            Assert.AreEqual(obj, "MCache3");

            MCache.Remove("mcache");
            obj = MCache.Get("mcache");
            Assert.IsNull(obj);

            MCache.Add("mcache", "MCache1", 1000);
        }
示例#2
0
文件: Auth.cs 项目: sfework/TM
        public static List <AuthModel> Get()
        {
            var Re = MCache.Get <List <AuthModel> >(MCache.MCacheTag.AuthList);

            if (Re == null)
            {
                var Ts = typeof(Auth).GetNestedTypes();
                Re = new List <AuthModel>();
                foreach (var T1 in Ts)
                {
                    var At   = (AuthTagAttribute)T1.GetCustomAttributes(true)[0];
                    var Temp = new Dictionary <string, int>();
                    foreach (var T2 in T1.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public))
                    {
                        Temp.Add(T2.Name, int.Parse(At.Prefix + ((int)T2.GetValue(null)).ToString().PadLeft(2, '0')));
                    }
                    Re.Add(new AuthModel {
                        Tag = At.Name, Auths = Temp
                    });
                }
                MCache.Set(MCache.MCacheTag.AuthList, Re);
            }
            return(Re);
        }