EngineComponentCache.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using Abp.UI;
  3. using IwbZero.ToolCommon;
  4. using IwbZero.ToolCommon.CacheHelpers;
  5. using IwbZero.ToolCommon.StringModel;
  6. namespace WeEngine.Components
  7. {
  8. public class EngineComponentCache : InfoCache<EngineComponent>
  9. {
  10. public static readonly EngineComponentCache Instance = new EngineComponentCache();
  11. public EngineComponentCache() : base(60* 24, 60* 1)
  12. {
  13. }
  14. public void SetCache(EngineComponent component)
  15. {
  16. Instance.AddCache(component.Id + "", component);
  17. }
  18. public EngineComponent GetCache(string id)
  19. {
  20. if (!Instance.TryGetCache(id, out var component))
  21. {
  22. try
  23. {
  24. string url = "";
  25. var result = url.RequestPost(new { Id = id }.Obj2String());
  26. component = result.Str2Obj<EngineComponent>();
  27. if (component != null)
  28. {
  29. SetCache(component);
  30. }
  31. }
  32. catch (Exception e)
  33. {
  34. throw new UserFriendlyException($"没有找到Id为{id}的引擎组件!{e.Message}");
  35. }
  36. }
  37. return component;
  38. }
  39. }
  40. }