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

loresoft / MediatR.CommandQuery / 11712653438

06 Nov 2024 10:05PM UTC coverage: 59.479%. Remained the same
11712653438

push

github

pwelter34
fix dependance issue

389 of 741 branches covered (52.5%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

1208 of 1944 relevant lines covered (62.14%)

19.58 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)
16
        : base(loggerFactory)
×
17
    {
18
        _hybridCache = hybridCache ?? throw new ArgumentNullException(nameof(hybridCache));
×
19
    }
×
20

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

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

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

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

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

© 2025 Coveralls, Inc