ContainerCacheStrategyFactory.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #region Apache License Version 2.0
  2. /*----------------------------------------------------------------
  3. Copyright 2019 Jeffrey Su & Suzhou Senparc Network Technology Co.,Ltd.
  4. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  5. except in compliance with the License. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software distributed under the
  8. License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  9. either express or implied. See the License for the specific language governing permissions
  10. and limitations under the License.
  11. Detail: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/license.md
  12. ----------------------------------------------------------------*/
  13. #endregion Apache License Version 2.0
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Text;
  18. using Senparc.CO2NET.Cache;
  19. using Senparc.Weixin.Containers;
  20. namespace Senparc.Weixin.Cache
  21. {
  22. public class ContainerCacheStrategyFactory
  23. {
  24. //internal static Func<IContainerCacheStrategy> ContainerCacheStrateFunc;
  25. //internal static Func<IContainerCacheStrategy> ObjectCacheStrateFunc = () => LocalContainerCacheStrategy.Instance;//默认为 WeixinLocalObjectCacheStrategy
  26. //internal static IBaseCacheStrategy<TKey, TValue> GetContainerCacheStrategy<TKey, TValue>()
  27. // where TKey : class
  28. // where TValue : class
  29. //{
  30. // return;
  31. //}
  32. ///// <summary>
  33. ///// 注册当前全局环境下的缓存策略
  34. ///// </summary>
  35. ///// <param name="func">如果为null,将使用默认的本地缓存策略(LocalObjectCacheStrategy.Instance)</param>
  36. //public static void RegisterContainerCacheStrategy(Func<IContainerCacheStrategy> func)
  37. //{
  38. // ObjectCacheStrateFunc = func;
  39. // //TODO:如果不考虑效率,此方法可以使用反射,自动注册所有的扩展缓存
  40. //}
  41. /// <summary>
  42. /// 如果
  43. /// </summary>
  44. /// <returns></returns>
  45. public static IContainerCacheStrategy GetContainerCacheStrategyInstance()
  46. {
  47. //从底层进行判断
  48. var containerCacheStrategy = CacheStrategyFactory.GetExtensionCacheStrategyInstance(ContainerCacheStrategyDomain.Instance)
  49. as IContainerCacheStrategy;
  50. return containerCacheStrategy;
  51. //if (ObjectCacheStrateFunc == null)
  52. //{
  53. // //默认状态
  54. // return LocalContainerCacheStrategy.Instance /*as IContainerCacheStrategy*/;
  55. //}
  56. //else
  57. //{
  58. // //自定义类型
  59. // var instance = ObjectCacheStrateFunc();// ?? LocalObjectCacheStrategy.Instance;
  60. // return instance;
  61. //}
  62. }
  63. }
  64. }