public virtual async Task <Store[]> GetByIdsAsync(string[] ids) { var cacheKey = CacheKey.With(GetType(), "GetByIdsAsync", string.Join("-", ids)); return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { var stores = new List <Store>(); using (var repository = RepositoryFactory()) { repository.DisableChangesTracking(); var dbStores = await repository.GetStoresByIdsAsync(ids); foreach (var dbStore in dbStores) { var store = AbstractTypeFactory <Store> .TryCreateInstance(); dbStore.ToModel(store); PopulateStore(store, dbStore); await SettingManager.DeepLoadSettingsAsync(store); stores.Add(store); cacheEntry.AddExpirationToken(StoreCacheRegion.CreateChangeToken(store)); } } var result = stores.ToArray(); var taskLoadDynamicPropertyValues = DynamicPropertyService.LoadDynamicPropertyValuesAsync(result); var taskLoadSeoForObjects = SeoService.LoadSeoForObjectsAsync(result); await Task.WhenAll(taskLoadDynamicPropertyValues, taskLoadSeoForObjects); return result; })); }
public virtual async Task <IEnumerable <ShoppingCart> > GetByIdsAsync(string[] cartIds, string responseGroup = null) { var retVal = new List <ShoppingCart>(); var cacheKey = CacheKey.With(GetType(), "GetByIdsAsync", string.Join("-", cartIds), responseGroup); return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { using (var repository = RepositoryFactory()) { //Disable DBContext change tracking for better performance repository.DisableChangesTracking(); var cartEntities = await repository.GetShoppingCartsByIdsAsync(cartIds, responseGroup); foreach (var cartEntity in cartEntities) { var cart = cartEntity.ToModel(AbstractTypeFactory <ShoppingCart> .TryCreateInstance()); //Calculate totals only for full responseGroup if (responseGroup == null) { TotalsCalculator.CalculateTotals(cart); } retVal.Add(cart); cacheEntry.AddExpirationToken(CartCacheRegion.CreateChangeToken(cart)); } } await DynamicPropertyService.LoadDynamicPropertyValuesAsync(retVal.ToArray <IHasDynamicProperties>()); return retVal; })); }
/// <summary> /// Return members by requested ids can be override for load extra data for resulting members /// </summary> /// <param name="memberIds"></param> /// <param name="responseGroup"></param> /// <param name="memberTypes"></param> /// <returns></returns> public virtual async Task <Member[]> GetByIdsAsync(string[] memberIds, string responseGroup = null, string[] memberTypes = null) { var cacheKey = CacheKey.With(GetType(), "GetByIdsAsync", string.Join("-", memberIds), responseGroup, memberTypes == null ? null : string.Join("-", memberTypes)); return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { var retVal = new List <Member>(); using (var repository = RepositoryFactory()) { repository.DisableChangesTracking(); //There is loading for all corresponding members conceptual model entities types //query performance when TPT inheritance used it is too slow, for improve performance we are passing concrete member types in to the repository var memberTypeInfos = AbstractTypeFactory <Member> .AllTypeInfos.Where(t => t.MappedType != null); if (memberTypes != null) { memberTypeInfos = memberTypeInfos.Where(x => memberTypes.Any(mt => x.IsAssignableTo(mt))); } memberTypes = memberTypeInfos.Select(t => t.MappedType.AssemblyQualifiedName).Distinct().ToArray(); var dataMembers = await repository.GetMembersByIdsAsync(memberIds, responseGroup, memberTypes); foreach (var dataMember in dataMembers) { var member = AbstractTypeFactory <Member> .TryCreateInstance(dataMember.MemberType); if (member != null) { dataMember.ToModel(member); retVal.Add(member); cacheEntry.AddExpirationToken(CustomerCacheRegion.CreateChangeToken(member)); } } } var taskDynamicProperty = DynamicPropertyService.LoadDynamicPropertyValuesAsync(retVal.ToArray <IHasDynamicProperties>()); var taskSeo = SeoService.LoadSeoForObjectsAsync(retVal.OfType <ISeoSupport>().ToArray()); await Task.WhenAll(taskDynamicProperty, taskSeo); return retVal.ToArray(); })); }