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

loresoft / MediatR.CommandQuery / 12567339125

01 Jan 2025 04:52AM UTC coverage: 60.229% (-0.1%) from 60.328%
12567339125

push

github

pwelter34
switch to Testcontainers

402 of 761 branches covered (52.83%)

Branch coverage included in aggregate %.

1282 of 2035 relevant lines covered (63.0%)

19.24 hits per line

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

0.0
/src/MediatR.CommandQuery/Behaviors/HybridCacheExpireBehavior.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
/// <summary>
9
/// A behavior for removing a cache tag of the response from <see cref="HybridCache"/>.
10
/// <typeparamref name="TRequest"/> must implement <see cref="ICacheExpire"/> for the cached tag.
11
/// </summary>
12
/// <typeparam name="TRequest">The type of the request.</typeparam>
13
/// <typeparam name="TResponse">The type of the response.</typeparam>
14
public partial class HybridCacheExpireBehavior<TRequest, TResponse> : PipelineBehaviorBase<TRequest, TResponse>
15
    where TRequest : class, IRequest<TResponse>
16
{
17
    private readonly HybridCache _hybridCache;
18

19
    /// <summary>
20
    /// Initializes a new instance of the <see cref="HybridCacheExpireBehavior{TRequest, TResponse}"/> class.
21
    /// </summary>
22
    /// <param name="loggerFactory">The logger factory.</param>
23
    /// <param name="hybridCache">The hybrid cache.</param>
24
    /// <exception cref="System.ArgumentNullException"></exception>
25
    public HybridCacheExpireBehavior(
26
        ILoggerFactory loggerFactory,
27
        HybridCache hybridCache)
28
        : base(loggerFactory)
×
29
    {
30
        ArgumentNullException.ThrowIfNull(hybridCache);
×
31

32
        _hybridCache = hybridCache;
×
33
    }
×
34

35
    /// <inheritdoc />
36
    protected override async Task<TResponse> Process(
37
        TRequest request,
38
        RequestHandlerDelegate<TResponse> next,
39
        CancellationToken cancellationToken)
40
    {
41
        ArgumentNullException.ThrowIfNull(request);
×
42
        ArgumentNullException.ThrowIfNull(next);
×
43

44
        var response = await next().ConfigureAwait(false);
×
45

46
        // expire cache
47
        if (request is not ICacheExpire cacheRequest)
×
48
            return response;
×
49

50
        var cacheTag = cacheRequest.GetCacheTag();
×
51
        if (!string.IsNullOrEmpty(cacheTag))
×
52
            await _hybridCache.RemoveByTagAsync(cacheTag, cancellationToken).ConfigureAwait(false);
×
53

54
        return response;
×
55
    }
×
56
}
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