From 43011457d678e79212467c3923a146e873d9e534 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Wed, 29 May 2024 05:50:47 +0300 Subject: [PATCH] feat: add wrap for save to cache --- Security/Services/AuthService.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Security/Services/AuthService.cs b/Security/Services/AuthService.cs index e13f565..90ceb14 100644 --- a/Security/Services/AuthService.cs +++ b/Security/Services/AuthService.cs @@ -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; -public class AuthService() +public class AuthService(ICacheService cache) { public TimeSpan Lifetime { private get; init; } @@ -10,4 +14,11 @@ public class AuthService() GeneratorKey.GenerateString(32); 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); } \ No newline at end of file