40 lines
937 B
C#
40 lines
937 B
C#
// Copyright (c) 2020 Tudor Stanciu
|
|
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using Tuitio.Domain.Models;
|
|
|
|
namespace Tuitio.Application.Stores
|
|
{
|
|
internal class TokenStore : ITokenStore
|
|
{
|
|
private ConcurrentDictionary<string, Token> Tokens { get; }
|
|
|
|
public TokenStore()
|
|
{
|
|
Tokens = new ConcurrentDictionary<string, Token>();
|
|
}
|
|
|
|
public Token Get(string key)
|
|
{
|
|
var registered = Tokens.ContainsKey(key);
|
|
if (!registered)
|
|
return null;
|
|
|
|
return Tokens[key];
|
|
}
|
|
|
|
public bool Set(string key, Token token)
|
|
{
|
|
var registered = Tokens.ContainsKey(key);
|
|
if (registered)
|
|
return false;
|
|
|
|
Tokens.TryAdd(key, token);
|
|
return true;
|
|
}
|
|
|
|
public void Remove(string key) => Tokens.Remove(key, out _);
|
|
}
|
|
}
|