using Newtonsoft.Json;
using System.Collections.Concurrent;
using System.Reflection;
using HealthMonitor.Util.Entities.Interfaces;
namespace HealthMonitor.Core.Cache
{
public class EntityCacheHandler : IEntityCacheHandler
{
///
/// 结构示例
/// {
/// "id_xxx": //实体的id值
/// [
/// "key_yyy_1", //缓存有该实体的缓存键
/// "key_yyy_2",
/// ...
/// ],
/// ...
/// }
///
private ConcurrentDictionary>> _mapper;
private readonly MethodInfo _m_GetPrimaryKey;
public int DurableSecond { get; private set; }
public Type EntityType { get; private set; }
public EntityCacheHandler(Type entityType, int durableSeconds)
{
EntityType = entityType;
DurableSecond = durableSeconds;
_mapper = new ConcurrentDictionary>>();
_m_GetPrimaryKey = entityType.GetMethod(nameof(IEntity.GetPrimaryKey))!;
}
public IEnumerable