ObjCacheProvider.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // ***********************************************************************
  2. // Assembly : Helper
  3. // Author : Administrator
  4. // Created : 12-21-2016
  5. //
  6. // Last Modified By : Administrator
  7. // Last Modified On : 12-22-2016
  8. // Contact :
  9. // File: ObjCacheProvider.cs
  10. // ***********************************************************************
  11. using System;
  12. namespace Infrastructure.Cache
  13. {
  14. /// <summary>
  15. /// 缓存工厂实现
  16. /// 这样做是方便换其他的缓存时(如memcachedContext)只换这一个地方即可
  17. /// </summary>
  18. public class ObjCacheProvider<T> : CacheProvider
  19. {
  20. public ObjCacheProvider()
  21. {
  22. SetCacheInstance(new CacheContext());
  23. }
  24. public bool Create(string key, T val, DateTime expire)
  25. {
  26. //设置缓存
  27. return CacheContext.Set<T>(key, val, expire);
  28. }
  29. /// <summary>
  30. /// 根据失效时间获取缓存
  31. /// <para>李玉宝于2016-11-08 16:54:04</para>
  32. /// </summary>
  33. /// <param name="key">The key.</param>
  34. public T GetCache(string key)
  35. {
  36. return CacheContext.Get<T>(key);
  37. }
  38. public void Remove(string key)
  39. {
  40. CacheContext.Remove(key);
  41. }
  42. }
  43. }