.Net Cache
生活随笔
收集整理的這篇文章主要介紹了
.Net Cache
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在.net中有兩個類實現了Cache
- HttpRuntime.Cache 應該程序使用的Cache,web也可以用
- HttpContext.Current.Cache ?web上下文的Cache對象,只能在Web上使用
?
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];} View Code?
轉載于:https://www.cnblogs.com/Blogs-Wang/p/6486832.html
總結
以上是生活随笔為你收集整理的.Net Cache的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学后感
- 下一篇: 【树莓派】修改树莓派盒子MAC地址