Stable user lockout, role and claim calls

This commit is contained in:
2026-10-10 18:14:31 +02:00
parent d3566c5e43
commit 381d5b7e94
11 changed files with 249 additions and 22 deletions
@@ -26,6 +26,31 @@ public sealed class UserCacheService(UserService service, IDistributedCache cach
public async Task<Result> DeleteUserRoleAsync(Guid targetUserId, Guid roleId, Guid userId, CancellationToken cancellationToken = default) =>
await service.DeleteUserRoleAsync(targetUserId, roleId, userId, cancellationToken);
public async Task<Result<Claim[]>> GetRoleClaimsAsync(Guid roleId, Guid userId, CancellationToken cancellationToken = default) =>
await Result.Try((Func<Task<Result<Claim[]>>>)(async () =>
{
if (!await featureManager.IsEnabledAsync(ServiceCachingFeature))
return await service.GetRoleClaimsAsync(roleId, userId, cancellationToken);
var cacheKey = HashService.ToMd5Hash($"getsystemroles-{userId}").Value;
var cached = await cache.GetStringAsync(cacheKey, cancellationToken);
if (string.IsNullOrWhiteSpace(cached))
{
var claimResult = await service.GetRoleClaimsAsync(roleId, userId, cancellationToken);
if (claimResult.IsFailed) return claimResult;
await cache.SetStringAsync(cacheKey, claimResult.Value.ToJson(),
cacheOptions, cancellationToken);
return claimResult;
}
return Result.Ok(cached.FromJson<Claim[]>());
}));
public async Task<Result<Role[]>> GetSystemRolesAsync(Guid userId, CancellationToken cancellationToken = default) =>
await Result.Try((Func<Task<Result<Role[]>>>)(async () =>
{