diff --git a/PARR.DAL/Cache/Services/CacheMatchingStatusService.cs b/PARR.DAL/Cache/Services/CacheMatchingStatusService.cs index 2293edac..f33c6ea3 100644 --- a/PARR.DAL/Cache/Services/CacheMatchingStatusService.cs +++ b/PARR.DAL/Cache/Services/CacheMatchingStatusService.cs @@ -1,4 +1,5 @@ -using PARR.DAL.Cache.Models; +using PARR.Constants; +using PARR.DAL.Cache.Models; using PARR.DAL.Cache.Services.Base; namespace PARR.DAL.Cache.Services @@ -12,34 +13,51 @@ namespace PARR.DAL.Cache.Services this.redisCacheService = redisCacheService; } - public Task DeleteCacheByJobGroupIdAsync(Guid jobGroupId) + public async Task DeleteCacheAsync(Guid id, SyncTaskEntityTypeEnum type) { - throw new NotImplementedException(); + var key = GetKey(id, type); + + await redisCacheService.DeleteCachedDataAsync(key); } - public Task DeleteCacheByJobIdAsync(Guid jobId) + + public async Task GetDataAsync(Guid id, SyncTaskEntityTypeEnum type) { - throw new NotImplementedException(); + var key = GetKey(id, type); + + return await redisCacheService.GetCachedDataAsync(key); } - public Task GetDataByJobGroupIdAsync(Guid jobGroupId) + + public async Task SetCacheAsync(Guid id, SyncTaskEntityTypeEnum type, MatchingStatusDto data, TimeSpan cacheDuration) { - throw new NotImplementedException(); + var key = GetKey(id, type); + + await redisCacheService.SetCachedDataAsync(key, data, cacheDuration); } - public Task GetDataByJobIdAsync(Guid jobId) + + private string GetKey(Guid id, SyncTaskEntityTypeEnum type) { - throw new NotImplementedException(); + var typeStr = ""; + switch (type) + { + case SyncTaskEntityTypeEnum.Job: + typeStr = "j"; + break; + case SyncTaskEntityTypeEnum.JobGroup: + typeStr = "g"; + break; + case SyncTaskEntityTypeEnum.Template: + typeStr = "t"; + break; + default: + break; + } + + return redisCacheService.GetKey(new string[] { "ms", typeStr, id.ToString() }); } - public Task SetCahcheByJobGroupIdAsync(Guid jobGroupId, MatchingStatusDto data) - { - throw new NotImplementedException(); - } - public Task SetCahcheByJobIdAsync(Guid jobId, MatchingStatusDto data) - { - throw new NotImplementedException(); - } } } diff --git a/PARR.DAL/Cache/Services/ICacheMatchingStatusService.cs b/PARR.DAL/Cache/Services/ICacheMatchingStatusService.cs index c0802569..976b766c 100644 --- a/PARR.DAL/Cache/Services/ICacheMatchingStatusService.cs +++ b/PARR.DAL/Cache/Services/ICacheMatchingStatusService.cs @@ -1,19 +1,18 @@ -using PARR.DAL.Cache.Models; +using PARR.Constants; +using PARR.DAL.Cache.Models; namespace PARR.DAL.Cache.Services { + /// + /// Сервис - статус matching`a + /// public interface ICacheMatchingStatusService { - Task GetDataByJobIdAsync(Guid jobId); + Task GetDataAsync(Guid id, SyncTaskEntityTypeEnum type); - Task GetDataByJobGroupIdAsync(Guid jobGroupId); + Task SetCacheAsync(Guid id, SyncTaskEntityTypeEnum type, MatchingStatusDto data, TimeSpan cacheDuration); - Task SetCahcheByJobIdAsync(Guid jobId, MatchingStatusDto data); + Task DeleteCacheAsync(Guid id, SyncTaskEntityTypeEnum type); - Task SetCahcheByJobGroupIdAsync(Guid jobGroupId, MatchingStatusDto data); - - Task DeleteCacheByJobIdAsync(Guid jobId); - - Task DeleteCacheByJobGroupIdAsync(Guid jobGroupId); } }