using Microsoft.EntityFrameworkCore; using System; 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, IEnumerable includes = null) where TEntity : class { var nameOfTEntity = typeof(TEntity).FullName; var cacheItem = cache.GetOrAdd(nameOfTEntity, (nameOfTEntity) => new CacheTableDataStore { NameOfTEntity = nameOfTEntity, Entities = new List(), }); var tableCache = new CacheTable(context, cacheItem, includes); return tableCache; } public void DropAll() => cache.Clear(); public void Drop() => cache.Remove(typeof(TEntity).FullName, out _); } }