Fix implementazione parametrica cache x servizi

This commit is contained in:
Samuele Locatelli
2026-03-17 11:35:38 +01:00
parent 0f61efdf58
commit 7c5adc9012
7 changed files with 56 additions and 47 deletions
@@ -14,6 +14,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
IConnectionMultiplexer redis,
ITemplateRowRepository repo) : base(config, redis)
{
_className = "TemplateRow";
_repo = repo;
}
@@ -28,7 +29,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<bool> CloneAsync(TemplateRowModel rec2clone)
{
return await TraceAsync("TemplateRow.Clone", async (activity) =>
return await TraceAsync($"{_className}.Clone", async (activity) =>
{
// eseguo clone
var result = await _repo.CloneAsync(rec2clone);
@@ -38,7 +39,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
{
// Invalido sia la lista classi che eventuali dettagli correlati
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return result;
});
@@ -51,7 +52,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<bool> DeleteAsync(TemplateRowModel rec2del)
{
return await TraceAsync("TemplateRow.Delete", async (activity) =>
return await TraceAsync($"{_className}.Delete", async (activity) =>
{
var dbResult = await _repo.GetRowAsync(rec2del.TemplateRowID);
if (dbResult == null) return false;
@@ -61,7 +62,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
@@ -75,7 +76,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<List<string>> FixRowUidAsync(int templateId)
{
return await TraceAsync("TemplateRow.FixRowUidAsync", async (activity) =>
return await TraceAsync($"{_className}.FixRowUidAsync", async (activity) =>
{
// 1. Recupero righe
var rows = await _repo.GetRowsAsync(templateId);
@@ -105,7 +106,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return result;
@@ -118,10 +119,10 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<List<TemplateRowModel>> GetAllAsync()
{
return await TraceAsync("TemplateRow.GetAll", async (activity) =>
return await TraceAsync($"{_className}.GetAll", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:TemplateRow:ALL",
$"{_redisBaseKey}:{_className}:ALL",
async () => await _repo.GetAllWithNavAsync(),
UltraLongCache
);
@@ -135,11 +136,10 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<List<TemplateRowModel>> GetByParentAsync(int templateId)
{
return await TraceAsync("TemplateRow.GetByParent", async (activity) =>
return await TraceAsync($"{_className}.GetByParent", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:TemplateRow:{templateId}",
$"{_redisBaseKey}:{_className}:{templateId}",
async () => await _repo.GetRowsAsync(templateId),
LongCache
);
@@ -148,7 +148,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
public async Task<bool> UpdateAwaitStateAsync(int templateRowId, bool? awaitBom, bool? awaitPrice, bool flushCache = false)
{
return await TraceAsync("TemplateRow.UpdateAwaitState", async (activity) =>
return await TraceAsync($"{_className}.UpdateAwaitState", async (activity) =>
{
var currRec = await _repo.GetRowAsync(templateRowId);
@@ -170,7 +170,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success && flushCache)
{
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
@@ -184,7 +184,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<bool> UpdateFileDataAsync(TemplateRowModel updRec)
{
return await TraceAsync("TemplateRow.UpdateFileData", async (activity) =>
return await TraceAsync($"{_className}.UpdateFileData", async (activity) =>
{
var currRec = await _repo.GetRowAsync(updRec.TemplateRowID);
@@ -205,7 +205,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
@@ -220,7 +220,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<bool> UpdateSerStructAsync(int TemplateRowID, string serStruct)
{
return await TraceAsync("TemplateRow.UpdateSerStruct", async (activity) =>
return await TraceAsync($"{_className}.UpdateSerStruct", async (activity) =>
{
var currRec = await _repo.GetRowAsync(TemplateRowID);
@@ -238,7 +238,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
@@ -252,7 +252,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<bool> UpsertAsync(TemplateRowModel upsRec)
{
return await TraceAsync("TemplateRow.Upsert", async (activity) =>
return await TraceAsync($"{_className}.Upsert", async (activity) =>
{
var currRec = await _repo.GetRowAsync(upsRec.TemplateRowID);
@@ -274,7 +274,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
@@ -285,6 +285,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
#region Private Fields
private readonly string _className;
private readonly ITemplateRowRepository _repo;
#endregion Private Fields
@@ -17,6 +17,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
IConnectionMultiplexer redis,
ITemplateRepository repo) : base(config, redis)
{
_className = "Template";
_repo = repo;
}
@@ -31,7 +32,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<bool> CloneAsync(TemplateModel rec2clone)
{
return await TraceAsync("Template.Clone", async (activity) =>
return await TraceAsync($"{_className}.Clone", async (activity) =>
{
// eseguo clone
var result = await _repo.CloneAsync(rec2clone);
@@ -40,7 +41,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (result)
{
// Invalido sia la lista classi che eventuali dettagli correlati
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
}
return result;
@@ -54,7 +55,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<bool> DeleteAsync(TemplateModel rec2del)
{
return await TraceAsync("Template.Delete", async (activity) =>
return await TraceAsync($"{_className}.Delete", async (activity) =>
{
var dbResult = await _repo.GetByIdAsync(rec2del.TemplateID);
if (dbResult == null) return false;
@@ -70,7 +71,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
bool success = await _repo.DeleteAsync(dbResult);
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
}
@@ -85,10 +86,10 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
public async Task<List<TemplateModel>> GetAllAsync()
{
// Uso helper TraceAsync che gestisce automaticamente StartActivity, Log e Exception tracking
return await TraceAsync("Template.GetAll", async (activity) =>
return await TraceAsync($"{_className}.GetAll", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:Template:ALL",
$"{_redisBaseKey}:{_className}:ALL",
async () => await _repo.GetAllWithNavAsync()
);
});
@@ -101,7 +102,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<bool> UpdateCostAsync(int templateId)
{
return await TraceAsync("Template.Upsert", async (activity) =>
return await TraceAsync($"{_className}.Upsert", async (activity) =>
{
// 1. Recupero dati
var rows = await _repo.GetRowsAsync(templateId);
@@ -150,7 +151,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (result)
{
// 4. Invalido cache
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
}
@@ -165,7 +166,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
/// <returns></returns>
public async Task<bool> UpsertAsync(TemplateModel upsRec)
{
return await TraceAsync("Template.Upsert", async (activity) =>
return await TraceAsync($"{_className}.Upsert", async (activity) =>
{
var currRec = await _repo.GetByIdAsync(upsRec.TemplateID);
@@ -185,7 +186,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:Template:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
await ClearCacheAsync($"{_redisBaseKey}:TemplateRows:*");
}
@@ -197,6 +198,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
#region Private Fields
private readonly string _className;
private readonly ITemplateRepository _repo;
#endregion Private Fields
@@ -14,8 +14,8 @@ namespace EgwCoreLib.Lux.Data.Services.Config
IConnectionMultiplexer redis,
IConfProfileRepository repo) : base(config, redis)
{
_repo = repo;
_className = "ConfProfile";
_repo = repo;
}
#endregion Public Constructors
@@ -14,8 +14,8 @@ namespace EgwCoreLib.Lux.Data.Services.Config
IConnectionMultiplexer redis,
IConfWoodRepository repo) : base(config, redis)
{
_repo = repo;
_className = "ConfWood";
_repo = repo;
}
#endregion Public Constructors
@@ -14,6 +14,7 @@ namespace EgwCoreLib.Lux.Data.Services.Config
IConnectionMultiplexer redis,
IEnvirParamRepository repo) : base(config, redis)
{
_className = "EnvirParam";
_repo = repo;
}
@@ -24,10 +25,10 @@ namespace EgwCoreLib.Lux.Data.Services.Config
public async Task<List<EnvirParamModel>> GetAllAsync()
{
// Uso helper TraceAsync che gestisce automaticamente StartActivity, Log e Exception tracking
return await TraceAsync("EnvirParam.GetAll", async (activity) =>
return await TraceAsync($"{_className}.GetAll", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:ConfEnvir",
$"{_redisBaseKey}:{_className}",
async () => await _repo.GetAllAsync(),
UltraLongCache
);
@@ -38,6 +39,7 @@ namespace EgwCoreLib.Lux.Data.Services.Config
#region Private Fields
private readonly string _className;
private readonly IEnvirParamRepository _repo;
#endregion Private Fields
@@ -14,6 +14,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
IConnectionMultiplexer redis,
IGenClassRepository repo) : base(config, redis)
{
_className = "GenClass";
_repo = repo;
}
@@ -23,7 +24,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
public async Task<bool> DeleteAsync(GenClassModel rec2del)
{
return await TraceAsync("GenClass.Delete", async (activity) =>
return await TraceAsync($"{_className}.Delete", async (activity) =>
{
var dbResult = await _repo.GetByCodeAsync(rec2del.ClassCod);
if (dbResult == null) return false;
@@ -40,7 +41,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:GenClass*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}*");
}
return success;
@@ -49,10 +50,10 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
public async Task<List<GenClassModel>> GetAllAsync()
{
return await TraceAsync("GenClass.GetAll", async (activity) =>
return await TraceAsync($"{_className}.GetAll", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:GenClass",
$"{_redisBaseKey}:{_className}",
async () => await _repo.GetAllAsync(),
UltraLongCache
);
@@ -61,7 +62,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
public async Task<bool> UpsertAsync(GenClassModel upsRec)
{
return await TraceAsync("GenClass.Upsert", async (activity) =>
return await TraceAsync($"{_className}.Upsert", async (activity) =>
{
var currRec = await _repo.GetByCodeAsync(upsRec.ClassCod);
@@ -81,7 +82,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:GenClass*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}*");
}
return success;
@@ -92,6 +93,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
#region Private Fields
private readonly string _className;
private readonly IGenClassRepository _repo;
#endregion Private Fields
@@ -14,6 +14,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
IConnectionMultiplexer redis,
IGenValRepository repo) : base(config, redis)
{
_className = "GenVal";
_repo = repo;
}
@@ -23,14 +24,14 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
public async Task<bool> DeleteAsync(GenValueModel rec2del)
{
return await TraceAsync("GenVal.Delete", async (activity) =>
return await TraceAsync($"{_className}.Delete", async (activity) =>
{
bool success = await _repo.DeleteAsync(rec2del);
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:GenClass*");
await ClearCacheAsync($"{_redisBaseKey}:GenVal:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
@@ -39,10 +40,10 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
public async Task<List<GenValueModel>> GetFiltAsync(string codClass)
{
return await TraceAsync("GenVal.GetFilt", async (activity) =>
return await TraceAsync($"{_className}.GetFilt", async (activity) =>
{
return await GetOrSetCacheAsync(
$"{_redisBaseKey}:GenVal:{codClass}",
$"{_redisBaseKey}:{_className}:{codClass}",
async () => await _repo.GetFiltAsync(codClass),
UltraLongCache
);
@@ -51,14 +52,14 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
public async Task<bool> MoveAsync(GenValueModel selRec, bool moveUp)
{
return await TraceAsync("GenVal.MoveAsync", async (activity) =>
return await TraceAsync($"{_className}.MoveAsync", async (activity) =>
{
bool success = await _repo.MoveAsync(selRec, moveUp);
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:GenClass*");
await ClearCacheAsync($"{_redisBaseKey}:GenVal:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
@@ -67,7 +68,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
public async Task<bool> UpsertAsync(GenValueModel upsRec)
{
return await TraceAsync("GenVal.Upsert", async (activity) =>
return await TraceAsync($"{_className}.Upsert", async (activity) =>
{
var currRec = await _repo.GetByIdAsync(upsRec.GenValID);
@@ -88,7 +89,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
if (success)
{
await ClearCacheAsync($"{_redisBaseKey}:GenClass*");
await ClearCacheAsync($"{_redisBaseKey}:GenVal:*");
await ClearCacheAsync($"{_redisBaseKey}:{_className}:*");
}
return success;
@@ -99,6 +100,7 @@ namespace EgwCoreLib.Lux.Data.Services.Utils
#region Private Fields
private readonly string _className;
private readonly IGenValRepository _repo;
#endregion Private Fields