.Net Cache
生活随笔
收集整理的這篇文章主要介紹了
.Net Cache
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在.net中有兩個類實現(xiàn)了Cache
- HttpRuntime.Cache 應該程序使用的Cache,web也可以用
- HttpContext.Current.Cache ?web上下文的Cache對象,只能在Web上使用
?
asp.net 頁面緩存的封裝
/// <summary>/// 根據(jù) cacheKey 獲取緩存內(nèi)容/// </summary>/// <param name="context">HttpContext</param>/// <param name="cacheName">key</param>/// <param name="cacheFunc">Func委托,該方法返回結(jié)果為要緩存的對象,當存在改緩存時,不會執(zhí)行該委托的方法</param>/// <param name="timeoutHours">單位:小時,默認值為12</param>/// <returns>緩存內(nèi)容</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];} View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/Blogs-Wang/p/6486832.html
總結(jié)
以上是生活随笔為你收集整理的.Net Cache的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学后感
- 下一篇: 详解设计模式之工厂模式(简单工厂+工厂方