コード例 #1
0
        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);
        }
コード例 #2
0
        protected virtual void ClearCache(IEnumerable <DemoProductPart> productParts)
        {
            foreach (var part in productParts)
            {
                DemoProductPartCacheRegion.ExpireEntity(part);
            }

            DemoProductPartSearchCacheRegion.ExpireRegion();
        }