asp.net下的缓存的一个实现以及.net下的HttpRuntime对象的属性

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Collections; using System.Web.Caching; namespace CCAS.BLL { publicclass CacheHelper { /// /// 建立缓存/// publicstaticobject TryAddCache(string key, objectvalue, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemovedCallback) { if (HttpRuntime.Cache[key] == null && value != null) return HttpRuntime.Cache.Add(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemovedCallback); elsereturnnull; } /// /// 获取缓存/// /// /// publicstaticobject GetCache(string key) { return HttpRuntime.Cache[key]; } /// /// 移除缓存/// publicstaticobject TryRemoveCache(string key) { if (HttpRuntime.Cache[key] != null) return HttpRuntime.Cache.Remove(key); elsereturnnull; } /// /// 移除键中带某关键字的缓存/// publicstaticvoid RemoveMultiCache(string keyInclude) { IDictionaryEnumerator CacheEnum = HttpRuntime.Cache.GetEnumerator(); while (CacheEnum.MoveNext()) { if (CacheEnum.Key.ToString().IndexOf(keyInclude.ToString()) >= 0) HttpRuntime.Cache.Remove(CacheEnum.Key.ToString()); } } /// /// 移除所有缓存/// publicstaticvoid RemoveAllCache() { IDictionaryEnumerator CacheEnum = HttpRuntime.Cache.GetEnumerator(); while (CacheEnum.MoveNext()) { HttpRuntime.Cache.Remove(CacheEnum.Key.ToString()); } } } }