using Microsoft.EntityFrameworkCore; using System.Collections.Concurrent; using System.Collections.Generic; namespace AsbCloudInfrastructure.Services.Cache { public class CacheDb { private readonly ConcurrentDictionary> cache = new ConcurrentDictionary>(); public CacheTable GetCachedTable(DbContext context) where TEntity : class { var entityTypeName = typeof(TEntity).FullName; if (!cache.ContainsKey(entityTypeName)) cache[entityTypeName] = new List(8); var tableCache = new CacheTable(context, (List)cache[entityTypeName]); return tableCache; } public void DropAll() => cache.Clear(); public void Drop() => cache.Remove(typeof(TEntity).FullName, out _); } }