public virtual async Task <DemoProductPart[]> GetByIdsAsync(string[] partIds) { var cacheKey = CacheKey.With(GetType(), nameof(GetByIdsAsync), string.Join("-", partIds.OrderBy(x => x))); var result = await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async cacheEntry => { var parts = Array.Empty <DemoProductPart>(); if (!partIds.IsNullOrEmpty()) { using var repository = (DemoCatalogRepository)_repositoryFactory(); //Optimize performance and CPU usage repository.DisableChangesTracking(); var entities = await repository.GetProductPartsByIdsAsync(partIds); parts = entities .Select(x => x.ToModel(AbstractTypeFactory <DemoProductPart> .TryCreateInstance())) .ToArray(); cacheEntry.AddExpirationToken(DemoProductPartCacheRegion.CreateChangeToken(partIds)); } return(parts); }); return(result); }
protected virtual void ClearCache(IEnumerable <DemoProductPart> productParts) { foreach (var part in productParts) { DemoProductPartCacheRegion.ExpireEntity(part); } DemoProductPartSearchCacheRegion.ExpireRegion(); }