using KBR.Shared.Cache.Models; using Microsoft.Extensions.Caching.Distributed; namespace KBR.Cache { public static class CacheHelpers { private static readonly string _userOtpSecrets = nameof(_userOtpSecrets); private static string UserOtpSecretKey(string key) => $"{_userOtpSecrets}-{key}"; public static async Task SetUserSecretsCacheAsync(IAppDistributedCache cache, string userId, string secret, CancellationToken cancellationToken = default) { await cache.SetAsync(UserOtpSecretKey(userId), secret, new DistributedCacheEntryOptions { AbsoluteExpiration = DateTime.UtcNow.AddMinutes(3) }, cancellationToken); } public static async Task GetUserOtpSecretAsync(IAppDistributedCache cache, string userId, CancellationToken cancellationToken = default) { var key = await cache.GetAsync(UserOtpSecretKey(userId), cancellationToken); return key; } } }