public async Task <IEnumerable <Post> > GetAllPostsAsync(short blogId)
    {
        var posts = await GetCachedValueAsync(
            () => _cache.GetPostsAsync(blogId, null),
            () => _repo.GetAllPostsAsync(blogId)
            );

        return(posts ?? new List <Post>());
    }
Exemple #2
0
    async Task UpdatePostCache(Blog blog)
    {
        var dbPosts = await _repo.GetAllPostsAsync(blog.Id);

        var cachePosts = await _cache.GetPostsAsync(blog.Id, null);

        var updatedPosts = dbPosts.Except(cachePosts.Item ?? new List <Post>());

        if (updatedPosts.Count() > 0)
        {
            await _cache.AddPostsAsync(updatedPosts);

            _logger.LogInformation("{service} pdated {count} posts(s)", nameof(BlogCacheProcessingService), updatedPosts.Count());
        }
    }