using System; using System.Collections.Generic; using System.Linq; using ChaosBot.Services; namespace ChaosBot.WebServer { public class AccessTokenCache : ICache { private Dictionary> _cache = new Dictionary>(); public void Invalidate() { DateTime now = DateTime.Now; _cache = _cache .Where(v => v.Value.Item2 > now) .ToDictionary(x => x.Key, x => x.Value); } public void Add(string key, string value, DateTime expires) { _cache.Add(key, new Tuple(value, expires)); } public void Remove(string key) { _cache.Remove(key); } public string Get(string key) { if (!_cache.TryGetValue(key, out Tuple data)) throw new KeyNotFoundException(); return data.Item1; } public bool HasKey(string key) { return _cache.ContainsKey(key); } public List GetKeys() { return _cache.Keys.ToList(); } } }