OptionsCache.cs 616 B

123456789101112131415161718192021222324
  1. using Fido2NetLib;
  2. using Microsoft.Extensions.Caching.Memory;
  3. namespace Passwordless;
  4. public class OptionsCache
  5. {
  6. private readonly IMemoryCache _cache;
  7. public OptionsCache(IMemoryCache cache)
  8. {
  9. _cache = cache;
  10. }
  11. public CredentialCreateOptions Get(string key)
  12. {
  13. return _cache.Get<CredentialCreateOptions>(key) ?? throw new Exception("Credential options not found - probably due to creation timeout");
  14. }
  15. public void Set(CredentialCreateOptions options)
  16. {
  17. _cache.Set(options.User.Name, options, TimeSpan.FromMinutes(5));
  18. }
  19. }