using Admin.NET.Plugin.AiDOP.Entity.DataPlatform; using Microsoft.Extensions.Caching.Memory; namespace Admin.NET.Plugin.AiDOP.DataPlatform; public sealed class MdpPullFieldMappingService : ITransient { private readonly ISqlSugarClient _db; private readonly IMemoryCache _cache; public MdpPullFieldMappingService(ISqlSugarClient db, IMemoryCache cache) { _db = db; _cache = cache; } public async Task> GetAsync(long entityId, CancellationToken cancellationToken = default) { var key = CacheKey(entityId); if (_cache.TryGetValue(key, out IReadOnlyList? cached) && cached != null) return cached; var list = await _db.Queryable() .Where(x => x.EntityId == entityId) .OrderBy(x => x.SortOrder) .OrderBy(x => x.Id) .ToListAsync(cancellationToken); IReadOnlyList frozen = list; _cache.Set(key, frozen, TimeSpan.FromSeconds(30)); return frozen; } public void Invalidate(long entityId) => _cache.Remove(CacheKey(entityId)); public static string CacheKey(long entityId) => $"mdp:pull-map:{entityId}"; }