.Net缓存

近期研究了一下.Net的缓存,据说可以提高系统的性能。

.Net缓存分为两种HttpRuntime.Cache和HttpContext.Current.Cache

不过从网上查找资料,说两种缓存其实是一样的,只是后者对前者进行了封装,在使用的时候推荐HttpRuntime.Cache的方式。

 1 //SetCache
 2 
 3 Cache objCache = HttpRuntime.Cache;
 4 objCache.Insert(CacheKey, objObject, dep, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(2));
 5 
 6 //GetCache
 7 
 8 System.Web.Caching.Cache objCache = HttpRuntime.Cache;
 9 return objCache[CacheKey];
10 
11 //RemoveCache
12 
13 System.Web.Caching.Cache objCache = HttpRuntime.Cache;
14 if (objCache != null)
15 {
16 if (objCache.Get(CacheKey) != null)
17 {
18 objCache.Remove(CacheKey);
19 }
20 }

 

posted @ 2013-12-30 14:12  kevin_h_wang  阅读(509)  评论(0编辑  收藏  举报