-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCacheInvalidationEventHandler.cs
More file actions
39 lines (32 loc) · 1.75 KB
/
Copy pathCacheInvalidationEventHandler.cs
File metadata and controls
39 lines (32 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#nullable enable
using TalentManagementAPI.Application.Common.Caching;
using TalentManagementAPI.Application.Interfaces.Caching;
namespace TalentManagementAPI.Application.Events.Handlers
{
public sealed class CacheInvalidationEventHandler :
IDomainEventHandler<EmployeeChangedEvent>,
IDomainEventHandler<DepartmentChangedEvent>,
IDomainEventHandler<PositionChangedEvent>,
IDomainEventHandler<SalaryRangeChangedEvent>
{
private readonly ICacheInvalidationService _cacheInvalidationService;
public CacheInvalidationEventHandler(ICacheInvalidationService cacheInvalidationService)
{
_cacheInvalidationService = cacheInvalidationService;
}
public async Task HandleAsync(EmployeeChangedEvent domainEvent, CancellationToken ct = default)
{
await _cacheInvalidationService.InvalidatePrefixAsync(CacheKeyPrefixes.EmployeesAll, ct);
await _cacheInvalidationService.InvalidateKeyAsync(CacheKeyPrefixes.DashboardMetrics, ct);
}
public Task HandleAsync(DepartmentChangedEvent domainEvent, CancellationToken ct = default)
=> _cacheInvalidationService.InvalidateKeyAsync(CacheKeyPrefixes.DashboardMetrics, ct);
public async Task HandleAsync(PositionChangedEvent domainEvent, CancellationToken ct = default)
{
await _cacheInvalidationService.InvalidatePrefixAsync(CacheKeyPrefixes.PositionsAll, ct);
await _cacheInvalidationService.InvalidateKeyAsync(CacheKeyPrefixes.DashboardMetrics, ct);
}
public Task HandleAsync(SalaryRangeChangedEvent domainEvent, CancellationToken ct = default)
=> _cacheInvalidationService.InvalidateKeyAsync(CacheKeyPrefixes.DashboardMetrics, ct);
}
}