64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using PARR.Constants;
|
|
using PARR.DAL.Cache.Models;
|
|
using PARR.DAL.Cache.Services.Base;
|
|
|
|
namespace PARR.DAL.Cache.Services
|
|
{
|
|
internal class CacheMatchingStatusService : ICacheMatchingStatusService
|
|
{
|
|
private readonly IRedisCacheService redisCacheService;
|
|
|
|
public CacheMatchingStatusService(IRedisCacheService redisCacheService)
|
|
{
|
|
this.redisCacheService = redisCacheService;
|
|
}
|
|
|
|
public async Task DeleteCacheAsync(Guid id, SyncTaskEntityTypeEnum type)
|
|
{
|
|
var key = GetKey(id, type);
|
|
|
|
await redisCacheService.DeleteCachedDataAsync(key);
|
|
}
|
|
|
|
|
|
public async Task<MatchingStatus?> GetDataAsync(Guid id, SyncTaskEntityTypeEnum type)
|
|
{
|
|
var key = GetKey(id, type);
|
|
|
|
return await redisCacheService.GetCachedDataAsync<MatchingStatus>(key);
|
|
}
|
|
|
|
|
|
public async Task SetCacheAsync(Guid id, SyncTaskEntityTypeEnum type, MatchingStatusDto data, TimeSpan cacheDuration)
|
|
{
|
|
var key = GetKey(id, type);
|
|
|
|
await redisCacheService.SetCachedDataAsync(key, data, cacheDuration);
|
|
}
|
|
|
|
|
|
private string GetKey(Guid id, SyncTaskEntityTypeEnum type)
|
|
{
|
|
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() });
|
|
}
|
|
|
|
|
|
}
|
|
}
|