public async Task <ProductAssociationSearchResult> SearchProductAssociationsAsync(ProductAssociationSearchCriteria criteria) { if (criteria == null) { throw new ArgumentNullException(nameof(criteria)); } var cacheKey = CacheKey.With(GetType(), "SearchProductAssociationsAsync", criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(AssociationSearchCacheRegion.CreateChangeToken()); var result = AbstractTypeFactory <ProductAssociationSearchResult> .TryCreateInstance(); if (!criteria.ObjectIds.IsNullOrEmpty()) { using (var repository = _catalogRepositoryFactory()) { //Optimize performance and CPU usage repository.DisableChangesTracking(); var dbResult = await repository.SearchAssociations(criteria); result.TotalCount = dbResult.TotalCount; result.Results = dbResult.Results .Select(x => x.ToModel(AbstractTypeFactory <ProductAssociation> .TryCreateInstance())).ToList(); } } return result; })); }
protected virtual void ClearCache(IEnumerable <CatalogProduct> entities) { AssociationSearchCacheRegion.ExpireRegion(); foreach (var entity in entities) { ItemCacheRegion.ExpireEntity(entity); } }
protected virtual void ClearCache(IEnumerable <Association> associations) { foreach (var association in associations) { AssociationCacheRegion.ExpireEntity(association); } AssociationSearchCacheRegion.ExpireRegion(); }
public async virtual Task <AssociationSearchResult> SearchAssociationsAsync(AssociationSearchCriteria criteria) { ValidateParameters(criteria); var cacheKey = CacheKey.With(GetType(), nameof(SearchAssociationsAsync), criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async cacheEntry => { cacheEntry.AddExpirationToken(AssociationSearchCacheRegion.CreateChangeToken()); var result = AbstractTypeFactory <AssociationSearchResult> .TryCreateInstance(); using (var associationsRepositoryFactory = _associationsRepositoryFactory()) { //Optimize performance and CPU usage associationsRepositoryFactory.DisableChangesTracking(); var sortInfos = BuildSortExpression(criteria); var query = BuildQuery(associationsRepositoryFactory, criteria); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0 && result.TotalCount > 0) { var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id) .Select(x => x.Id) .Skip(criteria.Skip).Take(criteria.Take) .AsNoTracking() .ToArrayAsync(); result.Results = (await _associationService.GetByIdsAsync(ids)).OrderBy(x => Array.IndexOf(ids, x.Id)).ToList(); } } return result; })); }
private void ClearCache(string[] ids) { ItemCacheRegion.ExpireProducts(ids); AssociationSearchCacheRegion.ExpireRegion(); }