在.net中有两个类实现了Cache
asp.net 页面缓存的封装
/// <summary> /// 根据 cacheKey 获取缓存内容 /// </summary> /// <param name="context">HttpContext</param> /// <param name="cacheName">key</param> /// <param name="cacheFunc">Func委托,该方法返回结果为要缓存的对象,当存在改缓存时,不会执行该委托的方法</param> /// <param name="timeoutHours">单位:小时,默认值为12</param> /// <returns>缓存内容</returns> public static Object GetCacheByName(HttpContextBase context,string cacheName,Func<object>cacheFunc,int timeoutHours=12) { if (context.Cache[cacheName] == null) { context.Cache.Insert(cacheName, cacheFunc.Invoke(), null, DateTime.Now.AddHours(timeoutHours), Cache.NoSlidingExpiration); } return context.Cache[cacheName]; }
原文:http://www.cnblogs.com/Blogs-Wang/p/6486832.html