CacheFactory.cs 1010 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using YiSha.Util;
  2. using YiSha.Cache.Interface;
  3. using YiSha.MemoryCache;
  4. using YiSha.RedisCache;
  5. namespace YiSha.Cache.Factory
  6. {
  7. public class CacheFactory
  8. {
  9. private static ICache cache = null;
  10. private static readonly object lockHelper = new object();
  11. public static ICache Cache
  12. {
  13. get
  14. {
  15. if (cache == null)
  16. {
  17. lock (lockHelper)
  18. {
  19. if (cache == null)
  20. {
  21. switch (GlobalContext.SystemConfig.CacheProvider)
  22. {
  23. case "Redis": cache = new RedisCacheImp(); break;
  24. default:
  25. case "Memory": cache = new MemoryCacheImp(); break;
  26. }
  27. }
  28. }
  29. }
  30. return cache;
  31. }
  32. }
  33. }
  34. }