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(ItemSearchCacheRegion.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) { ItemSearchCacheRegion.ExpireRegion(); foreach (var entity in entities) { ItemCacheRegion.ExpireEntity(entity); } }