-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathExtendedProviderAbilityCacheService.cs
More file actions
33 lines (28 loc) · 1.09 KB
/
ExtendedProviderAbilityCacheService.cs
File metadata and controls
33 lines (28 loc) · 1.09 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
using Bit.Core.AdminConsole.Entities.Provider;
using Bit.Core.AdminConsole.Models.Data.Provider;
using Bit.Core.AdminConsole.Repositories;
using Microsoft.Extensions.DependencyInjection;
using ZiggyCreatures.Caching.Fusion;
namespace Bit.Core.AdminConsole.AbilitiesCache;
public class ExtendedProviderAbilityCacheService(
[FromKeyedServices(ExtendedProviderAbilityCacheService.CacheName)] IFusionCache cache,
IProviderRepository providerRepository)
: IProviderAbilityCacheService
{
public const string CacheName = "ProviderAbilities";
public async Task<ProviderAbility?> GetProviderAbilityAsync(Guid providerId)
{
return await cache.GetOrSetAsync<ProviderAbility?>(
$"{providerId}",
async _ => await providerRepository.GetAbilityAsync(providerId)
);
}
public async Task UpsertProviderAbilityAsync(Provider provider)
{
await cache.SetAsync($"{provider.Id}", new ProviderAbility(provider));
}
public async Task DeleteProviderAbilityAsync(Guid providerId)
{
await cache.RemoveAsync($"{providerId}");
}
}