public async Task <ProductVideoSearchResult> SearchVideoLinksAsync(ProductVideoSearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), nameof(SearchVideoLinksAsync), criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(ProductVideoCacheRegion.CreateChangeToken()); var result = AbstractTypeFactory <ProductVideoSearchResult> .TryCreateInstance(); using (var repository = _repositoryFactory()) { var query = repository.VideoLinks.Where(x => criteria.ProductIds.Contains(x.ProductId)); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var videoLinksIds = await query.OrderByDescending(x => x.CreatedDate).Skip(criteria.Skip) .Take(criteria.Take) .Select(x => x.Id) .ToArrayAsync(); var priorResults = await _productVideoService.GetByIdsAsync(videoLinksIds); //TODO warning EF1001: Microsoft.EntityFrameworkCore.Internal.EnumerableExtensions is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. result.Results = priorResults; } return result; } })); }
public async Task <VideoLink[]> GetByIdsAsync(string[] videoLinksIds) { var cacheKey = CacheKey.With(GetType(), nameof(GetByIdsAsync), string.Join("-", videoLinksIds)); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(ProductVideoCacheRegion.CreateChangeToken()); using (var repository = _repositoryFactory()) { repository.DisableChangesTracking(); var links = await repository.GetByIdsAsync(videoLinksIds); return links.Select(x => x.ToModel(AbstractTypeFactory <VideoLink> .TryCreateInstance())).ToArray(); } })); }
protected virtual void ClearCache() { ProductVideoCacheRegion.ExpireRegion(); }