protected virtual void ClearCache(IEnumerable <DemoProductPart> productParts)
        {
            foreach (var part in productParts)
            {
                DemoProductPartCacheRegion.ExpireEntity(part);
            }

            DemoProductPartSearchCacheRegion.ExpireRegion();
        }
        public virtual async Task <DemoProductPartSearchResult> SearchProductPartsAsync(DemoProductPartSearchCriteria criteria)
        {
            ValidateParameters(criteria);

            var cacheKey = CacheKey.With(GetType(), nameof(SearchProductPartsAsync), criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async cacheEntry =>
            {
                cacheEntry.AddExpirationToken(DemoProductPartSearchCacheRegion.CreateChangeToken());

                var result = AbstractTypeFactory <DemoProductPartSearchResult> .TryCreateInstance();

                using (var catalogRepository = _repositoryFactory())
                {
                    //Optimize performance and CPU usage
                    catalogRepository.DisableChangesTracking();
                    var sortInfos = BuildSortExpression(criteria);
                    var query = BuildQuery(catalogRepository, 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 _productPartService.GetByIdsAsync(ids)).OrderBy(x => Array.IndexOf(ids, x.Id)).ToList();
                    }
                }

                return result;
            }));
        }