RuntimePackageCache.cs 830 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using IwbZero.ToolCommon.CacheHelpers;
  3. namespace WeEngine
  4. {
  5. /// <summary>
  6. /// 运行态方案包缓存
  7. /// </summary>
  8. public class RuntimePackageCache : InfoCache<RuntimePackage>
  9. {
  10. public static RuntimePackageCache Instance = new RuntimePackageCache();
  11. public RuntimePackageCache() : base(60 * 24, 60)
  12. {
  13. }
  14. public virtual void SetCache(RuntimePackage runPackage)
  15. {
  16. Instance.AddCache(runPackage.Id + "", runPackage);
  17. }
  18. public virtual RuntimePackage GetCache(string runId)
  19. {
  20. if(!Instance.TryGetCache(runId, out var runtimePackage))
  21. {
  22. throw new Exception($"没有找到key为{runId}的缓存");
  23. }
  24. return runtimePackage;
  25. }
  26. }
  27. }