Stable user lockout, role and claim calls
This commit is contained in:
@@ -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 () =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user