public override async Task ClearCacheAsync() { await _cacheManager.RemoveByPrefixAsync(EntityHelper.GetCachePrefix <Product>()); await _cacheManager.RemoveByPrefixAsync(EntityHelper.GetCachePrefix <Cart>()); await base.ClearCacheAsync(); }
public async Task <ReviewEvaluation> EvaluateAsync(ReviewFilter filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } async Task <ReviewEvaluation> acquire() { var query = GetQuery(filter); var evaluation = new ReviewEvaluation { TotalCount = await query.CountAsync(), TotalRating1 = await query.CountAsync(x => x.Rating == 1), TotalRating2 = await query.CountAsync(x => x.Rating == 2), TotalRating3 = await query.CountAsync(x => x.Rating == 3), TotalRating4 = await query.CountAsync(x => x.Rating == 4), TotalRating5 = await query.CountAsync(x => x.Rating == 5) }; evaluation.AverageRating = CalculateRatingAverage( evaluation.TotalCount, evaluation.TotalRating1, evaluation.TotalRating2, evaluation.TotalRating3, evaluation.TotalRating4, evaluation.TotalRating5); evaluation.PercentRating1 = CalculateRatingPercent(evaluation.TotalCount, evaluation.TotalRating1); evaluation.PercentRating2 = CalculateRatingPercent(evaluation.TotalCount, evaluation.TotalRating2); evaluation.PercentRating3 = CalculateRatingPercent(evaluation.TotalCount, evaluation.TotalRating3); evaluation.PercentRating4 = CalculateRatingPercent(evaluation.TotalCount, evaluation.TotalRating4); evaluation.PercentRating5 = CalculateRatingPercent(evaluation.TotalCount, evaluation.TotalRating5); return(evaluation); } string key = await _cacheManager.ComposeKeyAsync($"{EntityHelper.GetCachePrefix<Review>()}.{nameof(EvaluateAsync)}", filter); var result = await _cacheManager.GetAsync(key, acquire); return(result); }
public async Task <CountEvaluation> EvaluateAsync(BannerFilter filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } async Task <CountEvaluation> acquire() { var query = GetQuery(filter); return(InternalEvaluate(count: await query.CountAsync())); } string key = await _cacheManager.ComposeKeyAsync($"{EntityHelper.GetCachePrefix<Banner>()}.{nameof(EvaluateAsync)}", filter); var result = await _cacheManager.GetAsync(key, acquire); return(result); }
public async Task <AmountEvaluation> EvaluateAsync(ProductFilter filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } async Task <AmountEvaluation> acquire() { var query = GetQuery(filter); return(InternalEvaluate(amount: await query.Select(x => x.Price).SumAsync(), quantity: await query.CountAsync(), count: await query.CountAsync())); } string key = await _cacheManager.ComposeKeyAsync($"{EntityHelper.GetCachePrefix<Product>()}.{nameof(EvaluateAsync)}", filter); var result = await _cacheManager.GetAsync(key, acquire); return(result); }
public virtual async Task ClearCacheAsync() { await _cacheManager.RemoveByPrefixAsync(EntityHelper.GetCachePrefix <TEntity>()); }