public async Task <Product[]> GetRecommendationsAsync(RecommendationEvalContext context)
        {
            var dynamicAssociationsContext = context as DynamicAssociationsEvalContext;

            if (dynamicAssociationsContext == null)
            {
                throw new InvalidCastException(nameof(context));
            }

            var cacheKey = CacheKey.With(GetType(), nameof(GetRecommendationsAsync), context.GetCacheKey());

            return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(RecommendationsCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());

                var result = new List <Product>();
                var recommendedProductIds = await _associationsApi.EvaluateDynamicAssociationsAsync(dynamicAssociationsContext.ToContextDto());

                if (recommendedProductIds != null)
                {
                    result.AddRange(await _catalogService.GetProductsAsync(recommendedProductIds.ToArray(), ItemResponseGroup.Seo | ItemResponseGroup.Outlines | ItemResponseGroup.ItemWithPrices | ItemResponseGroup.ItemWithDiscounts | ItemResponseGroup.Inventory));
                }

                return result.ToArray();
            }));
        }
        public async Task <Product[]> GetRecommendationsAsync(Model.Recommendations.RecommendationEvalContext context)
        {
            var cognitiveContext = context as CognitiveRecommendationEvalContext;

            if (cognitiveContext == null)
            {
                throw new InvalidCastException(nameof(context));
            }

            var cacheKey = CacheKey.With(GetType(), "GetRecommendationsAsync", context.GetHashCode().ToString());

            return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(RecommendationsCacheRegion.CreateChangeToken());

                var result = new List <Product>();
                var recommendedProductIds = await _recommendationsApi.GetRecommendationsAsync(cognitiveContext.ToContextDto());
                if (recommendedProductIds != null)
                {
                    result.AddRange(await _catalogService.GetProductsAsync(recommendedProductIds.ToArray(), ItemResponseGroup.Seo | ItemResponseGroup.Outlines | ItemResponseGroup.ItemWithPrices | ItemResponseGroup.ItemWithDiscounts | ItemResponseGroup.Inventory));
                }
                return result.ToArray();
            }));
        }