异步
var cache= await _cacheManager.GetCache("OrganCache").GetAsync<string, List<OrganListDto>>("OrganCache"+ "_"+input.Level, async f => { var q = from r in _repository.GetAll().Where(x => x.Level == input.Level) //.WhereIf(input.FatherId > 0, x => x.FatherId == input.FatherId) select r; var re= await q.AsNoTracking().ToListAsync(); return re.MapTo<List<OrganListDto>>(); });
同步
BroadcastDeviceCtrl getCtrl = _cacheManager.GetCache("BroadcastCache").Get<string, BroadcastDevice>(key, f => { RecordBroadcast broadcast = _recordBroadcastRepository.GetAll().FirstOrDefault(x => x.Id == Guid.Parse(key)); return new BroadcastDevice(Guid.Parse(key), broadcast.Manufacturer, _recordIpRepository.GetAll().FirstOrDefault(x => x.BroadcastId == broadcast.Id && x.IsInnerIp)?.IpAddress, broadcast.MacAddr, broadcast.CtrPortJson); }).GetCtrl;