public async Task <List <Item> > GetItemPricesFromApi() { var ids = await _apiRepository.FetchAllItemIdsFromApi(CancellationToken.None); var filter = new List <int>(); var items = new List <Item>(); var cachedItems = new List <Item>(); var itemPrices = new List <ItemPrice>(); foreach (var id in ids.ToArray()) { if (await _cacheRepository.CheckIfCached(id)) { var cachedItem = await _cacheRepository.ReadFromCache(id); filter.Add(id); cachedItems.Add(cachedItem); } } items.AddRange(await _apiRepository.FetchAllItemsFromApi(CancellationToken.None, filter.ToArray())); itemPrices.AddRange(await _apiRepository.FetchAllItemPricesFromApi(CancellationToken.None, filter.ToArray())); foreach (var item in items) { var itemPrice = itemPrices.FirstOrDefault(x => x.ItemPriceId == item.Id); if (itemPrice != null) { item.BuyData = itemPrice.BuyData; item.SellData = itemPrice.SellData; } } items.ForEach(async x => await _cacheRepository.WriteToCache(x)); items = items.Concat(cachedItems).ToList(); return(items); }