// 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 Tokens { get; } public TokenStore() { Tokens = new ConcurrentDictionary(); } 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 _); } }