DataCache.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Web;
  3. namespace Ant.Service.Utilities
  4. {
  5. /// <summary>
  6. /// 缓存相关的操作类
  7. /// </summary>
  8. public class DataCache
  9. {
  10. /// <summary>
  11. /// 获取当前应用程序指定CacheKey的Cache值
  12. /// </summary>
  13. /// <param name="CacheKey"></param>
  14. /// <returns></returns>
  15. public static object GetCache(string CacheKey)
  16. {
  17. System.Web.Caching.Cache objCache = HttpRuntime.Cache;
  18. return objCache[CacheKey];
  19. }
  20. /// <summary>
  21. /// 设置当前应用程序指定CacheKey的Cache值
  22. /// </summary>
  23. /// <param name="CacheKey"></param>
  24. /// <param name="objObject"></param>
  25. public static void SetCache(string CacheKey, object objObject)
  26. {
  27. System.Web.Caching.Cache objCache = HttpRuntime.Cache;
  28. objCache.Insert(CacheKey, objObject);
  29. }
  30. /// <summary>
  31. /// 设置当前应用程序指定CacheKey的Cache值
  32. /// </summary>
  33. /// <param name="CacheKey"></param>
  34. /// <param name="objObject"></param>
  35. public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration,TimeSpan slidingExpiration )
  36. {
  37. System.Web.Caching.Cache objCache = HttpRuntime.Cache;
  38. objCache.Insert(CacheKey, objObject,null,absoluteExpiration,slidingExpiration);
  39. }
  40. }
  41. }