/// <summary> /// This either searches the ranking in in-memory cache or calcualate the new one from searchProvider. /// </summary> /// <param name="searchString"></param> /// <param name="url"></param> /// <param name="searchOption"></param> /// <returns> /// Async - The List of ranking for various keyword seperated by comma. /// </returns> private async Task <List <int> > LookupRankingByKeyword(string searchString, string url, int searchOption) { var rankingList = new List <int>(); string[] words = searchString.Split(","); var ratingService = RatingService.ExecuteCreation((SearchType)searchOption, url); foreach (var word in words) { if (!_cache.TryGetValue($"{word}-{url}-{searchOption}", out int ranking)) { Console.WriteLine("Cache miss....loading from service into cache"); var result = await ratingService.GetRanking(word); rankingList.Add(result); ranking = result; _cache.Set($"{word}-{url}-{searchOption}", ranking, _options); } else { Console.WriteLine("Cache hit"); Response.Headers.Add("CACHE", "true"); rankingList.Add(ranking); } } return(rankingList); }