private async Task <IReadOnlyDictionary <string, EnrolledBalance> > GetEnrolledBalancesAsync(IEnumerable <WalletBalance> balances) { var walletKeys = balances.Select(x => new DepositWalletKey ( blockchainAssetId: x.AssetId, blockchainType: _blockchainType, depositWalletAddress: x.Address )); return((await _enrolledBalanceRepository.GetAsync(walletKeys)) .ToDictionary( x => GetEnrolledBalancesDictionaryKey(x.Key.DepositWalletAddress, x.Key.BlockchainAssetId), y => y)); }
public async Task <IEnumerable <EnrolledBalance> > GetAsync(IEnumerable <DepositWalletKey> keys) { List <EnrolledBalance> balances = new List <EnrolledBalance>(keys.Count()); List <DepositWalletKey> askFromDbAgain = new List <DepositWalletKey>(keys.Count()); foreach (var key in keys) { if (_memCache.TryGetValue(key, out var balance)) { balances.Add(balance as EnrolledBalance); } else { askFromDbAgain.Add(key); } } if (askFromDbAgain.Any()) { var fromDb = (await _enrolledBalanceRepository.GetAsync(askFromDbAgain))?.ToList(); if (fromDb != null && fromDb.Any()) { fromDb.ForEach((item) => { using (var entry = _memCache.CreateEntry(item.Key)) { entry.Value = item; } }); balances.AddRange(fromDb); } } return(balances); }