feat(core, infrastructure): UnitService - удаление/массовое удаление юнитов
This commit is contained in:
@@ -158,6 +158,13 @@
|
||||
/// <returns></returns>
|
||||
Task<List<T>> GetHashFieldsAsync<T>(List<(string HashKey, string FieldKey)> keys, bool useCompression = false);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить список из Hash
|
||||
/// </summary>
|
||||
/// <param name="keys"></param>
|
||||
/// <returns></returns>
|
||||
Task DeleteHashFieldsAsync(List<(string HashKey, string FieldKey)> keys);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,11 +125,32 @@ namespace PARR.Core.Services.UnitService.Implementations
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public Task RemoveFromCacheAsync(Guid id)
|
||||
public async Task RemoveFromCacheAsync(Guid id)
|
||||
{
|
||||
//todo: может удалять тоже списком
|
||||
var hashKey = redisCacheService.GetKey(CacheKeys.Unit.UnitHashWithBucket(id));
|
||||
var unitKey = redisCacheService.GetKey(CacheKeys.Unit.UnitItem(id));
|
||||
|
||||
throw new NotImplementedException();
|
||||
await redisCacheService.DeleteHashFieldAsync(hashKey, unitKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить записи UnitInfo из кэш
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task RemoveFromCacheAsync(IReadOnlySet<Guid> ids)
|
||||
{
|
||||
if (ids == null || ids.Count == 0)
|
||||
return;
|
||||
|
||||
// Формируем ключи
|
||||
var keys = ids.Select(t =>
|
||||
{
|
||||
var (hashKey, fieldKey) = (redisCacheService.GetKey(CacheKeys.Unit.UnitHashWithBucket(t)), redisCacheService.GetKey(CacheKeys.Unit.UnitItem(t)));
|
||||
return (HashKey: hashKey, FieldKey: fieldKey);
|
||||
}).ToList();
|
||||
|
||||
await redisCacheService.DeleteHashFieldsAsync(keys);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,5 +36,13 @@ namespace PARR.Core.Services.UnitService.Implementations
|
||||
{
|
||||
await unitCacheService.RemoveFromCacheAsync(id);
|
||||
}
|
||||
|
||||
public async Task RemoveFromCacheAsync(IEnumerable<Guid> ids)
|
||||
{
|
||||
// Защищаем себя от Multiple Enumeration и убираем дубликаты, если передали List
|
||||
var uniqueIds = ids as IReadOnlySet<Guid> ?? ids.ToHashSet();
|
||||
|
||||
await unitCacheService.RemoveFromCacheAsync(uniqueIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,11 @@ namespace PARR.Core.Services.UnitService.Interfaces
|
||||
/// <returns></returns>
|
||||
Task RemoveFromCacheAsync(Guid id);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Удалить юниты из кэша
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveFromCacheAsync(IEnumerable<Guid> ids);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user