public virtual async Task <GenericSearchResult <Store> > SearchStoresAsync(StoreSearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchStoresAsync", criteria.GetCacheKey()); return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(StoreSearchCacheRegion.CreateChangeToken()); var result = new GenericSearchResult <Store>(); using (var repository = RepositoryFactory()) { var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "Name" } }; } var query = GetStoresQuery(repository, criteria, sortInfos); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var storeIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); result.Results = (await StoreService.GetByIdsAsync(storeIds)).AsQueryable().OrderBySortInfos(sortInfos).ToList(); } } return result; })); }
private void ClearCache(IEnumerable <Store> stores) { StoreSearchCacheRegion.ExpireRegion(); foreach (var store in stores) { StoreCacheRegion.ExpireStore(store); } }
protected virtual void ClearCache(IEnumerable <Store> stores) { StoreSearchCacheRegion.ExpireRegion(); foreach (var store in stores) { StoreCacheRegion.ExpireStore(store); } }
public async Task <GenericSearchResult <Store> > SearchStoresAsync(StoreSearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchStoresAsync", criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(StoreSearchCacheRegion.CreateChangeToken()); var result = new GenericSearchResult <Store>(); using (var repository = _repositoryFactory()) { var query = repository.Stores; if (!string.IsNullOrEmpty(criteria.Keyword)) { query = query.Where(x => x.Name.Contains(criteria.Keyword) || x.Id.Contains(criteria.Keyword)); } if (!criteria.StoreIds.IsNullOrEmpty()) { query = query.Where(x => criteria.StoreIds.Contains(x.Id)); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "Name" } }; } 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 <Store> .TryCreateInstance())).ToList(); } return result; })); }