内存级的缓存实际上引用
static void Main(string[] args) { var x = System.DateTime.Now; MemoryCache mc = new MemoryCache("my"); var t = new testNumber() { I = 1 }; mc.Add(new CacheItem("i", t), new CacheItemPolicy { SlidingExpiration = new TimeSpan(1, 1, 1) }); mc.Add(new CacheItem("j", t), new CacheItemPolicy { SlidingExpiration = new TimeSpan(1, 1, 1) }); t.I = 2; var s = (testNumber)mc.Get("i"); var s2 = (testNumber)mc.Get("j"); Thread ta = new Thread(() => { //mc = new MemoryCache("my"); var k = (testNumber)mc.Get("i"); var k2 = (testNumber)mc.Get("j"); k.I++; Console.WriteLine("In thread:" + k.I); Console.WriteLine("In thread:" + k2.I); }); ta.Start(); Thread.Sleep(1000); Console.WriteLine(s2.I); Console.WriteLine(s.I); Console.ReadKey(); } class testNumber { public int I { get; set; } }