国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 石台县| 萨嘎县| 昌江| 西青区| 高安市| 灵宝市| 南开区| 大宁县| 观塘区| 自贡市| 买车| 新田县| 玉溪市| 瓮安县| 鄂尔多斯市| 霍州市| 怀仁县| 晋州市| 金昌市| 弥渡县| 大同市| 轮台县| 大英县| 巴彦县| 昂仁县| 张家港市| 和林格尔县| 茶陵县| 锡林浩特市| 杭锦后旗| 和田县| 屏边| 华亭县| 利津县| 那坡县| 汶川县| 天镇县| 龙井市| 和田市| 武义县| 武鸣县|