public async Task <IEnumerable <Video> > GetVideosInCategoryAsync(short categoryId, string[] roles) { var videos = await GetCachedValueAsync( () => _cache.GetVideosAsync(roles, categoryId), () => _repo.GetVideosInCategoryAsync(categoryId, roles) ); return(videos ?? new List <Video>()); }
async Task UpdateVideoCache(Category category, string[] allRoles) { var dbVideos = await _repo.GetVideosInCategoryAsync(category.Id, allRoles); var cacheVideos = await _cache.GetVideosAsync(allRoles, category.Id); var updatedVideos = dbVideos.Except(cacheVideos.Item ?? new List <Video>()); if (updatedVideos.Count() > 0) { var securedVideos = updatedVideos.Select(video => new SecuredResource <Video>( video, allRoles )); await _cache.AddVideosAsync(securedVideos); } }