Cite this
using System.Runtime.Caching;
/// <Summary> /// Get the data cache /// </ Summary> /// <param name = "Key"> Key key_ method name rule identification field _ </ param> public static Object GetCache ( String key) { ObjectCache cache = MemoryCache.Default; var value = cache[key]; return value; } /// <summary> /// 缓存值 /// </summary> /// <param name="key">键</param> /// <param name="value">值</param> /// <param name="ExpirationTime">过期时间</param> public static void SetCache(string key, object value, int ExpirationTime = 6000) { if (GetCache(key) != null) { return; } ObjectCache cache = MemoryCache.Default; CacheItemPolicy policy = new CacheItemPolicy { AbsoluteExpiration = new new the DateTimeOffset (DateTime.Now.AddSeconds (The ExpirationTime)) // set the expiration time }; cache.Set(key, value, policy); }