コード例 #1
0
    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>());
    }
コード例 #2
0
    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);
        }
    }