feat: add wrap for save to cache

This commit is contained in:
Polianin Nikita 2024-05-29 05:50:47 +03:00
parent 4240ad8110
commit 43011457d6

View File

@ -1,8 +1,12 @@
using System; using Mirea.Api.Security.Common.Domain;
using Mirea.Api.Security.Common.Dto.Requests;
using Mirea.Api.Security.Common.Dto.Responses;
using Mirea.Api.Security.Common.Interfaces;
using System;
namespace Mirea.Api.Security.Services; namespace Mirea.Api.Security.Services;
public class AuthService() public class AuthService(ICacheService cache)
{ {
public TimeSpan Lifetime { private get; init; } public TimeSpan Lifetime { private get; init; }
@ -10,4 +14,11 @@ public class AuthService()
GeneratorKey.GenerateString(32); GeneratorKey.GenerateString(32);
private static string GetAuthCacheKey(string fingerprint) => $"{fingerprint}_auth_token"; private static string GetAuthCacheKey(string fingerprint) => $"{fingerprint}_auth_token";
private Task SetAuthTokenDataToCache(string fingerprint, AuthToken data, CancellationToken cancellation) =>
cache.SetAsync(
GetAuthCacheKey(fingerprint),
JsonSerializer.SerializeToUtf8Bytes(data),
slidingExpiration: Lifetime,
cancellationToken: cancellation);
} }