1 /// <summary> 2 /// 获取数据缓存 3 /// </summary> 4 /// <param name="CacheKey">键</param> 5 public static object GetCache(string CacheKey) 6 { 7 System.Web.Caching.Cache objCache = HttpRuntime.Cache; 8 return objCache[CacheKey]; 9 } 10 /// <summary> 11 /// 设置数据缓存 12 /// </summary> 13 public static void SetCache(string CacheKey, object objObject) 14 { 15 System.Web.Caching.Cache objCache = HttpRuntime.Cache; 16 objCache.Insert(CacheKey, objObject); 17 } 18 /// <summary> 19 /// 设置数据缓存 20 /// </summary> 21 public static void SetCache(string CacheKey, object objObject, TimeSpan Timeout) 22 { 23 System.Web.Caching.Cache objCache = HttpRuntime.Cache; 24 objCache.Insert(CacheKey, objObject, null, DateTime.MaxValue, Timeout, System.Web.Caching.CacheItemPriority.NotRemovable, null); 25 } 26 /// <summary> 27 /// 设置数据缓存 28 /// </summary> 29 public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration) 30 { 31 System.Web.Caching.Cache objCache = HttpRuntime.Cache; 32 objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration); 33 } 34 /// <summary> 35 /// 移除指定数据缓存 36 /// </summary> 37 public static void RemoveAllCache(string CacheKey) 38 { 39 System.Web.Caching.Cache _cache = HttpRuntime.Cache; 40 _cache.Remove(CacheKey); 41 } 42 /// <summary> 43 /// 移除全部缓存 44 /// </summary> 45 public static void RemoveAllCache() 46 { 47 System.Web.Caching.Cache _cache = HttpRuntime.Cache; 48 IDictionaryEnumerator CacheEnum = _cache.GetEnumerator(); 49 while (CacheEnum.MoveNext()) 50 { 51 _cache.Remove(CacheEnum.Key.ToString()); 52 } 53 }