public virtual async Task EvaluateDiscountsAsync(PromotionEvaluationContext context, IEnumerable <IDiscountable> owners) { var cacheKey = CacheKey.With(GetType(), "EvaluateDiscountsAsync", context.GetCacheKey()); var rewards = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(MarketingCacheRegion.CreateChangeToken()); cacheEntry.SetAbsoluteExpiration(TimeSpan.FromMinutes(1)); var contextDto = context.ToPromotionEvaluationContextDto(); return(await _promiotionApi.EvaluatePromotionsAsync(contextDto)); }); ApplyRewards(rewards, owners); }
public virtual async Task EvaluateDiscountsAsync(PromotionEvaluationContext context, IEnumerable <IDiscountable> owners) { var cacheKey = CacheKey.With(GetType(), "EvaluateDiscountsAsync", context.GetCacheKey()); var rewards = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(MarketingCacheRegion.CreateChangeToken()); //Workaround: Use lifetime for promotions from ChangesPollingInterval setting to be able manage this value cacheEntry.SetAbsoluteExpiration(_storefrontOptions.ChangesPollingInterval); var contextDto = context.ToPromotionEvaluationContextDto(); return(await _promiotionApi.EvaluatePromotionsAsync(contextDto)); }); ApplyRewards(rewards, owners); }