ObjectCache cache = MemoryCache.Default; //1 string cacheData1 = cache["key1"] as string;//得不到数据 //2 //string cacheData1 = Convert.ToString(cache["key1"]);//这个ok CacheItemPolicy policy1 = new CacheItemPolicy(); policy1.AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddMinutes(30)); cache.Set("key1", 10, policy1); Response.Write($"{cacheData1}
"); Response.End();