using ECMJobRunner.Application.Common.Dtos;
using System.Collections.Concurrent;
namespace ECMJobRunner.WebCron.ProfileWorker;
///
/// Thread-safe cache for storing active profile configurations.
/// Used to track profile state and detect changes in schedule or removal.
///
public class ProfileCache
{
private readonly ConcurrentDictionary _cache = new();
public CfgProfileDto? Get(string jobId) => _cache.TryGetValue(jobId, out var profile) ? profile : null;
public void AddOrUpdate(string jobId, CfgProfileDto profile) => _cache[jobId] = profile;
public bool TryRemove(string jobId, out CfgProfileDto? profile) => _cache.TryRemove(jobId, out profile);
public IEnumerable GetAllJobIds() => _cache.Keys;
public bool TryGetValue(string jobId, out CfgProfileDto? profile) => _cache.TryGetValue(jobId, out profile);
}