DictionaryCache.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Bowin.Common.Cache;
  2. using Bowin.Common.JSON;
  3. using Bowin.Common.Utility;
  4. using Microsoft.Extensions.Caching.Memory;
  5. using Microsoft.Extensions.Options;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Z.EntityFramework.Plus;
  12. namespace YLShipBuildLandMap.Entity.ViewModel
  13. {
  14. public static class DictionaryCache
  15. {
  16. public static Task<SysDictionaryItem> GetDictionaryItem(string dictionaryCode, int value)
  17. {
  18. var key = "DicItem_" + dictionaryCode + "_" + value.ToString();
  19. var json = (string)CacheHelper.Get(key);
  20. if (json != null)
  21. {
  22. return Task.FromResult(json.ToObject<SysDictionaryItem>());
  23. }
  24. var dbContext = YLShipBuildLandMapContext.New();
  25. var dic = dbContext.SysDictionaryItem.Where(x => x.DictionaryCode == dictionaryCode && x.Value == value).FirstOrDefault();
  26. CacheHelper.Add(key, dic.ToJson(), DateTime.Now.AddMinutes(1));
  27. return Task.FromResult(dic);
  28. }
  29. }
  30. }