示例#1
0
        public async Task <IPagedList <CustomerReview> > SearchReviewsAsync(CustomerReviewSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), nameof(SearchReviewsAsync), criteria.GetCacheKey());

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

                var apiChangeToken = _apiChangesWatcher.CreateChangeToken();
                cacheEntry.AddExpirationToken(apiChangeToken);

                var searchCriteriaDto = criteria.ToApiSearchCriteria();
                var foundCustomerReviews = await _customerReviewsApi.SearchCustomerReviewsAsync(searchCriteriaDto);
                var totalCount = foundCustomerReviews.TotalCount ?? 0;

                var customerReviews =
                    foundCustomerReviews.Results.Select(customerReview => customerReview.ToCustomerReview());
                return new StaticPagedList <CustomerReview>(
                    customerReviews,
                    criteria.PageNumber,
                    criteria.PageSize,
                    totalCount);
            }));
        }
示例#2
0
        public async Task <IPagedList <Model.CustomerReviews.CustomerReview> > SearchReviewsAsync(CustomerReviewSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), nameof(SearchReviewsAsync), criteria.GetCacheKey());

            return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(CustomerReviewCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());
                var result = await _customerReviewsApi.SearchCustomerReviewsAsync(criteria.ToSearchCriteriaDto());
                return new StaticPagedList <Model.CustomerReviews.CustomerReview>(result.Results.Select(x => x.ToCustomerReview()),
                                                                                  criteria.PageNumber, criteria.PageSize, result.TotalCount.Value);
            }));
        }