DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/Cache/CacheDb.cs

26 lines
766 B
C#
Raw Normal View History

2021-04-07 18:01:56 +05:00
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using System;
using System.Collections.Generic;
using System.Text;
namespace AsbCloudInfrastructure.Services.Cache
{
public class CacheDb
{
private Dictionary<Type, IEnumerable<object>> cache = new Dictionary<Type, IEnumerable<object>>();
public ICacheTable<TEntity> GetCachedTable<TEntity>(DbContext context)
where TEntity : class
{
var entityType = typeof(TEntity);
if (!cache.ContainsKey(entityType))
cache[entityType] = new List<TEntity>(8);
var tableCache = new CacheTable<TEntity>(context, (List<TEntity>)cache[entityType]);
return tableCache;
}
}
}