using Bowin.Common.Cache; using Bowin.Common.JSON; using Bowin.Common.Utility; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Z.EntityFramework.Plus; namespace YLShipBuildLandMap.Entity.ViewModel { public static class DictionaryCache { public static Task GetDictionaryItem(string dictionaryCode, int value) { var key = "DicItem_" + dictionaryCode + "_" + value.ToString(); var json = (string)CacheHelper.Get(key); if (json != null) { return Task.FromResult(json.ToObject()); } var dbContext = YLShipBuildLandMapContext.New(); var dic = dbContext.SysDictionaryItem.Where(x => x.DictionaryCode == dictionaryCode && x.Value == value).FirstOrDefault(); CacheHelper.Add(key, dic.ToJson(), DateTime.Now.AddMinutes(1)); return Task.FromResult(dic); } } }