ApplicationCache.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* 作者: 季健国
  2. * 创建时间: 2012/7/19 21:47:20
  3. *
  4. */
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Web;
  10. namespace Ant.Service.Common
  11. {
  12. public interface ICache
  13. {
  14. /// <summary>
  15. /// 获取全局应用缓存
  16. /// </summary>
  17. /// <param name="key"></param>
  18. /// <returns></returns>
  19. object GetApplicationCache(string key);
  20. /// <summary>
  21. /// 设置全局应用缓存
  22. /// </summary>
  23. /// <param name="key"></param>
  24. /// <param name="obj"></param>
  25. void SetApplicationCache(string key, object obj);
  26. /// <summary>
  27. /// 删除全局应用缓存
  28. /// </summary>
  29. /// <param name="key"></param>
  30. void RemoveApplicationCache(string key);
  31. }
  32. /// <summary>
  33. /// 全局应用缓存
  34. /// </summary>
  35. public class ApplicationCache:ICache
  36. {
  37. #region ICache 成员
  38. public object GetApplicationCache(string key)
  39. {
  40. return HttpContext.Current.Application[key];
  41. }
  42. public void SetApplicationCache(string key, object obj)
  43. {
  44. HttpContext.Current.Application.Add(key, obj);
  45. }
  46. public void RemoveApplicationCache(string key)
  47. {
  48. HttpContext.Current.Application.Remove(key);
  49. }
  50. #endregion
  51. }
  52. }