ASP.NET Cache 操作
/// <summary> /// 设置当前应用程序指定Key的Cache值 /// </summary> /// <param name="Key"></param> /// <param name="value"></param> /// <param name="time">过期时间 DateTime.Now.AddMinutes(10D)</param> public static void SetAbsoluteCache(string key, object value, double minutes) { HttpRuntime.Cache.Insert(key, value, null, DateTime.Now.AddMinutes(minutes), Cache.NoSlidingExpiration); } public static void SetAbsoluteCache(string key, object value, double minutes, CacheItemPriority priority, CacheItemRemovedCallback callBack) { HttpRuntime.Cache.Insert(key, value, null, DateTime.Now.AddMinutes(minutes), Cache.NoSlidingExpiration, priority, callBack); } public static void SetAbsoluteCache(string key, object value, CacheDependency dependencies, double minutes) { HttpRuntime.Cache.Insert(key, value, dependencies, DateTime.Now.AddMinutes(minutes), Cache.NoSlidingExpiration); } public static void SetAbsoluteCache(string key, object value, CacheDependency dependencies, double minutes, CacheItemPriority priority, CacheItemRemovedCallback callBack) { HttpRuntime.Cache.Insert(key, value, dependencies, DateTime.Now.AddMinutes(minutes), Cache.NoSlidingExpiration, priority, callBack); } /// <summary> /// 设置当前应用程序指定Key的Cache值 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="time">相对过期时间 TimeSpan.FromMinutes(10D)</param> public static void SetSlidingCache(string key, object value, double minutes) { HttpRuntime.Cache.Insert(key, value, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(minutes)); } public static void SetSlidingCache(string key, object value, double minutes, CacheItemPriority priority, CacheItemRemovedCallback callBack) { HttpRuntime.Cache.Insert(key, value, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(minutes), priority, callBack); } public static void SetSlidingCache(string key, object value, CacheDependency dependencies, double minutes) { HttpRuntime.Cache.Insert(key, value, dependencies, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(minutes)); } public static void SetSlidingCache(string key, object value, CacheDependency dependencies, double minutes, CacheItemPriority priority, CacheItemRemovedCallback callBack) { HttpRuntime.Cache.Insert(key, value, dependencies, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(minutes), priority, callBack); }