using System.Collections; using System.Collections.Concurrent; using Elsa.Http.Services; using Microsoft.Extensions.Caching.Memory; namespace Elsa.Http.Implementations; public class RouteTable : IRouteTable { private static readonly object Key = new(); private readonly IMemoryCache _cache; public RouteTable(IMemoryCache cache) => _cache = cache; private ConcurrentDictionary Routes => _cache.GetOrCreate(Key, _ => new ConcurrentDictionary()); public void Add(string path) => Routes.TryAdd(path, path); public void Remove(string path) => Routes.TryRemove(path, out _); public void AddRange(IEnumerable paths) { foreach (var path in paths) Add(path); } public void RemoveRange(IEnumerable paths) { foreach (var path in paths) Remove(path); } public IEnumerator GetEnumerator() => Routes.Values.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }