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

loresoft / MediatR.CommandQuery / 11418431610

19 Oct 2024 02:43PM UTC coverage: 58.337% (+0.9%) from 57.424%
11418431610

push

github

pwelter34
add HybridCache, misc refactors

331 of 675 branches covered (49.04%)

Branch coverage included in aggregate %.

28 of 176 new or added lines in 24 files covered. (15.91%)

156 existing lines in 33 files now uncovered.

1163 of 1886 relevant lines covered (61.66%)

19.49 hits per line

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

0.0
/src/MediatR.CommandQuery/Behaviors/HybridCacheQueryBehavior.cs
1
using MediatR.CommandQuery.Definitions;
2

3
using Microsoft.Extensions.Caching.Hybrid;
4
using Microsoft.Extensions.Logging;
5

6
namespace MediatR.CommandQuery.Behaviors;
7

8
public partial class HybridCacheQueryBehavior<TRequest, TResponse> : PipelineBehaviorBase<TRequest, TResponse>
9
    where TRequest : class, IRequest<TResponse>
10
{
11
    private readonly HybridCache _hybridCache;
12

13
    public HybridCacheQueryBehavior(
14
        ILoggerFactory loggerFactory,
15
        HybridCache hybridCache)
NEW
16
        : base(loggerFactory)
×
17
    {
NEW
18
        _hybridCache = hybridCache ?? throw new ArgumentNullException(nameof(hybridCache));
×
NEW
19
    }
×
20

21
    protected override async Task<TResponse> Process(
22
        TRequest request,
23
        RequestHandlerDelegate<TResponse> next,
24
        CancellationToken cancellationToken)
25
    {
NEW
26
        ArgumentNullException.ThrowIfNull(request);
×
NEW
27
        ArgumentNullException.ThrowIfNull(next);
×
28

29
        // cache only if implements interface
NEW
30
        var cacheRequest = request as ICacheResult;
×
NEW
31
        if (cacheRequest?.IsCacheable() != true)
×
NEW
32
            return await next().ConfigureAwait(false);
×
33

NEW
34
        var cacheKey = cacheRequest.GetCacheKey();
×
NEW
35
        var cacheTag = cacheRequest.GetCacheTag();
×
36

NEW
37
        var cacheOptions = new HybridCacheEntryOptions
×
NEW
38
        {
×
NEW
39
            Expiration = cacheRequest.SlidingExpiration(),
×
NEW
40
            LocalCacheExpiration = cacheRequest.SlidingExpiration(),
×
NEW
41
        };
×
42

NEW
43
        return await _hybridCache.GetOrCreateAsync(
×
NEW
44
            key: cacheKey,
×
NEW
45
            factory: async token => await next().ConfigureAwait(false),
×
NEW
46
            options: cacheOptions,
×
NEW
47
            tags: string.IsNullOrEmpty(cacheTag) ? null : [cacheTag],
×
NEW
48
            cancellationToken: cancellationToken);
×
NEW
49
    }
×
50
}
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