国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET緩存處理類實例

2024-07-10 13:29:09
字體:
供稿:網(wǎng)友

這篇文章主要介紹了ASP.NET緩存處理類,實例分析了asp.net緩存的使用技巧,需要的朋友可以參考下

本文實例講述了ASP.NET緩存處理類。分享給大家供大家參考。具體如下:

ASP.NET 緩存處理類。

用法:

Just copy this code into a new class file (.cs) and add it to your ASP .NET website. One thing to keep in mind is that data stored in ASP .NET Cache can be accessible across all sessions. So when creating a cacheID for the object to be stored, it must be unique (or it could be overwritten). I usually store the unique cacheID in the session and then use that to referrence the cacheID. (e.g. CacheHandler.Write(Session["MyCacheData"], myData);)

具體代碼如下:

 

 
  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Web.Caching; 
  4. using System.Web; 
  5. /// <summary> 
  6. /// This class reads/writes to ASP .NET server cache. For the sake of  
  7. /// simplicity, the class writes objects to cache with no expirateion. 
  8. /// Use the Remove() function to programmatically remove objects stored 
  9. /// from the server cache. This class was created as an alternative to  
  10. /// storing large objects in the session. 
  11. /// </summary> 
  12. public class CacheHandler 
  13. public static bool Write(string cacheID, object data) 
  14. if (HttpContext.Current == null
  15. return false
  16. if (cacheID == null || cacheID.Equals("")) 
  17. return false
  18. HttpRuntime.Cache.Insert( 
  19. cacheID, data, null, Cache.NoAbsoluteExpiration,  
  20. Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null 
  21. ); 
  22. return true
  23. public static object Read(string cacheID) 
  24. if (HttpContext.Current == null
  25. return null
  26. return HttpRuntime.Cache.Get(cacheID); 
  27. public static void Remove(string cacheID) 
  28. if (HttpContext.Current == null ) 
  29. return
  30. if (cacheID == null || cacheID.Equals("")) 
  31. return
  32. HttpRuntime.Cache.Remove(cacheID); 

希望本文所述對大家的asp.net程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 庆安县| 轮台县| 浏阳市| 普宁市| 隆子县| 商洛市| 清水河县| 苏尼特左旗| 昌乐县| 武乡县| 万载县| 灵川县| 蓬安县| 湟中县| 墨江| 武威市| 阿拉尔市| 桓仁| 防城港市| 紫金县| 澄江县| 龙口市| 焉耆| 长垣县| 兴业县| 黎川县| 海南省| 芦山县| 库伦旗| 新安县| 竹北市| 南汇区| 鲁山县| 乳源| 营山县| 胶州市| 临漳县| 宜阳县| 金平| 沈丘县| 图木舒克市|