CacheHelper.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Reflection;
  6. using System.Configuration;
  7. namespace Bowin.Common.Cache
  8. {
  9. public static class CacheHelper
  10. {
  11. static readonly ICacheProvider cacheProvider = new HttpCacheProvider();
  12. static CacheHelper()
  13. {
  14. try
  15. {
  16. cacheProvider = (ICacheProvider)(typeof(ICacheProvider).Assembly.CreateInstance(ConfigurationManager.AppSettings["CacheProvider"]));
  17. }
  18. catch
  19. { }
  20. }
  21. public static object Add(string key, object entry)
  22. {
  23. return cacheProvider.Add(key, entry,DateTime.Now.AddHours(1f));
  24. }
  25. public static object Add(string key, object entry, DateTime utcExpiry)
  26. {
  27. return cacheProvider.Add(key, entry, utcExpiry);
  28. }
  29. public static object Get(string key)
  30. {
  31. return cacheProvider.Get(key);
  32. }
  33. public static void Remove(string key)
  34. {
  35. cacheProvider.Remove(key);
  36. }
  37. public static void Set(string key, object entry)
  38. {
  39. cacheProvider.Set(key, entry, DateTime.UtcNow.AddHours(1f));
  40. }
  41. public static void Set(string key, object entry, DateTime utcExpiry)
  42. {
  43. cacheProvider.Set(key, entry, utcExpiry);
  44. }
  45. }
  46. }