forked from ddrilling/AsbCloudServer
26 lines
766 B
C#
26 lines
766 B
C#
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|