• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vposd / CachedQueries / 4055301632

pending completion
4055301632

Pull #16

github

GitHub
Merge 0046186a7 into 541d6e495
Pull Request #16: Release 1.0.16

2 of 28 branches covered (7.14%)

Branch coverage included in aggregate %.

88 of 88 new or added lines in 7 files covered. (100.0%)

19 of 182 relevant lines covered (10.44%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

31.58
/src/CachedQueries.Core/DefaultCacheInvalidator.cs
1
using CachedQueries.Core.Interfaces;
2

3
namespace CachedQueries.Core;
4

5
public class DefaultCacheInvalidator : ICacheInvalidator
6
{
7
    private readonly ICacheStore _cache;
8

9
    public DefaultCacheInvalidator(ICacheStore cache)
4✔
10
    {
4✔
11
        _cache = cache;
4✔
12
    }
4✔
13

14
    /// <summary>
15
    /// Async remove all cache entries linked to provided invalidation tags
16
    /// </summary>
17
    /// <param name="tags">Invalidation tags</param>
18
    /// <param name="cancellationToken"></param>
19
    public async Task InvalidateCacheAsync(IEnumerable<string> tags, CancellationToken cancellationToken = default)
20
    {
×
21
        var tagsList = tags.ToList();
×
22
        var keysToRemove = new List<string>(tagsList);
×
23

24
        var tagsToExpireTasks = tagsList.Distinct()
×
25
            .Select(tagKey => _cache.GetAsync<List<string>>(tagKey, false, cancellationToken))
×
26
            .ToList();
×
27

28
        await Task.WhenAll(tagsToExpireTasks);
×
29

30
        foreach (var list in tagsToExpireTasks.Select(x => x.Result ?? new List<string>()))
×
31
            keysToRemove.AddRange(list);
×
32

33
        var tasks = keysToRemove
×
34
            .Distinct()
×
35
            .Select(item => _cache.DeleteAsync(item, false, cancellationToken));
×
36

37
        await Task.WhenAll(tasks);
×
38
    }
×
39

40
    /// <summary>
41
    ///     Async link invalidation tags to cache key
42
    /// </summary>
43
    /// <param name="key">Cache key</param>
44
    /// <param name="tags">Invalidation tags</param>
45
    /// <param name="cancellationToken"></param>
46
    public async Task LinkTagsAsync(string key, IEnumerable<string> tags,
47
        CancellationToken cancellationToken)
48
    {
4✔
49
        if (string.IsNullOrWhiteSpace(key))
4✔
50
            return;
3✔
51

52
        var tagsToLink = tags.Distinct().ToList();
1✔
53

54
        async Task LinkTagAsync(string tag)
55
        {
×
56
            var list = await _cache.GetAsync<List<string>>(tag, false, cancellationToken) ?? new List<string>();
×
57

58
            if (!list.Contains(key))
×
59
                list.Add(key);
×
60

61
            await _cache.SetAsync(tag, list.Distinct(), false, null, cancellationToken);
×
62
        }
×
63

64
        await Task.WhenAll(tagsToLink.Select(LinkTagAsync));
1✔
65
    }
4✔
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc