public virtual async Task <GenericSearchResult <InventoryInfo> > SearchInventoriesAsync(InventorySearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchInventoriesAsync", criteria.GetCacheKey()); return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(InventorySearchCacheRegion.CreateChangeToken()); var result = new GenericSearchResult <InventoryInfo>(); using (var repository = RepositoryFactory()) { repository.DisableChangesTracking(); var sortInfos = GetSortInfos(criteria); var query = GetQuery(repository, criteria, sortInfos); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var inventoryIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); result.Results = (await InventoryService.GetByIdsAsync(inventoryIds, criteria.ResponseGroup)).AsQueryable().OrderBySortInfos(sortInfos).ToArray(); } } return result; })); }
protected virtual void ClearCache(IEnumerable <InventoryInfo> inventories) { InventorySearchCacheRegion.ExpireRegion(); foreach (var inventory in inventories) { InventoryCacheRegion.ExpireInventory(inventory); } }
public async Task <GenericSearchResult <InventoryInfo> > SearchInventoriesAsync(InventorySearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchInventoriesAsync", criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(InventorySearchCacheRegion.CreateChangeToken()); var result = new GenericSearchResult <InventoryInfo>(); using (var repository = _repositoryFactory()) { repository.DisableChangesTracking(); var query = repository.Inventories; if (!criteria.ProductIds.IsNullOrEmpty()) { query = query.Where(x => criteria.ProductIds.Contains(x.Sku)); } if (!criteria.FulfillmentCenterIds.IsNullOrEmpty()) { query = query.Where(x => criteria.FulfillmentCenterIds.Contains(x.FulfillmentCenterId)); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "ModifiedDate" } }; } query = query.OrderBySortInfos(sortInfos); result.TotalCount = await query.CountAsync(); var list = await query.Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); result.Results = list.Select(x => x.ToModel(AbstractTypeFactory <InventoryInfo> .TryCreateInstance())).ToList(); } return result; })); }