Fix durate random cache

This commit is contained in:
Samuele Locatelli
2026-05-28 12:27:40 +02:00
parent e424218b01
commit a1447c38c3
+23 -22
View File
@@ -213,7 +213,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "AnagStatiCommAsync",
cacheKey: Utils.redisStatoCom,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () =>
await dbController.AnagStatiCommAsync() ?? new List<ListValuesModel>(),
tagList: [Utils.redisStatoCom]
@@ -229,7 +229,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "AnagTipoArtLvAsync",
cacheKey: Utils.redisTipoArt,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.AnagTipoArtLvAsync() ?? new List<ListValuesModel>(),
tagList: [Utils.redisTipoArt]
);
@@ -244,7 +244,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "ArticleWithDossierAsync",
cacheKey: Utils.redisArtByDossier,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await Task.FromResult(dbController.ArticleWithDossier()) ?? new List<string>(),
tagList: [Utils.redisArtByDossier]
);
@@ -280,7 +280,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "ArticoliGetByTipoAsync",
cacheKey: redisKey,
expiration: TimeSpan.FromMinutes(2),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () =>
await dbController.ArticoliGetByTipoAsync(tipo, azienda) ?? new List<AnagArticoliModel>(),
tagList: [Utils.redisArtList, $"{Utils.redisArtList}:Tipo"]
@@ -302,7 +302,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "ArticoliGetSearchAsync",
cacheKey: redisKey,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () =>
await dbController.ArticoliGetSearchAsync(numRecord, tipoArt, azienda, searchVal) ?? new List<AnagArticoliModel>(),
tagList: [Utils.redisArtList, $"{Utils.redisArtList}:Search"]
@@ -422,7 +422,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "ConfigGetAllAsync",
cacheKey: Utils.redisConfKey,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.ConfigGetAllAsync() ?? new List<ConfigModel>(),
tagList: [Utils.redisConfKey]
);
@@ -571,7 +571,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "DossiersGetLastFiltAsync",
cacheKey: currKey,
expiration: TimeSpan.FromMinutes(redisLongTimeCache / 5),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.DossiersGetLastFiltAsync(IdxMacchina, CodArticolo, DtStart, DtEnd, MaxRec) ?? new List<DossierModel>(),
tagList: [Utils.redisDossByMac]
);
@@ -644,7 +644,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "ElencoAziendeAsync",
cacheKey: $"{Utils.redisAnagGruppi}:Aziende",
expiration: TimeSpan.FromMinutes(redisLongTimeCache * 2),
expiration: getRandTOut(redisLongTimeCache * 2),
fetchFunc: async () =>
await dbController.AnagGruppiAziendeAsync() ?? new List<AnagGruppiModel>(),
tagList: [Utils.redisAnagGruppi, $"{Utils.redisAnagGruppi}:Aziende"]
@@ -660,7 +660,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "ElencoGruppiFaseAsync",
cacheKey: $"{Utils.redisAnagGruppi}:FASE",
expiration: TimeSpan.FromMinutes(redisLongTimeCache / 5),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.AnagGruppiFaseAsync() ?? new List<AnagGruppiModel>(),
tagList: [Utils.redisAnagGruppi]
);
@@ -676,7 +676,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "ElencoLinkAsync",
cacheKey: Utils.redisLinkMenu,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.ElencoLinkAsync() ?? new List<LinkMenuModel>(),
tagList: [Utils.redisLinkMenu]
);
@@ -1111,7 +1111,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "FluxLogParetoAsync",
cacheKey: redKey,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.FluxLogParetoAsync(idxMacchina, dtFrom, dtTo) ?? new List<ParetoFluxLogDTO>(),
tagList: [Utils.redisParetoFLKey]
);
@@ -1257,7 +1257,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "IstKitFiltAsync",
cacheKey: currKey,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.IstKitFiltAsync(keyKit, keyExtOrd) ?? new List<IstanzeKitModel>(),
tagList: [Utils.redisKitInst]
);
@@ -1318,7 +1318,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "ListGiacenzeAsync",
cacheKey: currKey,
expiration: TimeSpan.FromSeconds(redisShortTimeCache),
expiration: getRandTOut(redisShortTimeCache),
fetchFunc: async () => await dbController.ListGiacenzeAsync(IdxOdl) ?? new List<AnagGiacenzeModel>(),
tagList: [Utils.redisGiacenzaList]
);
@@ -1423,7 +1423,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "MacchineGetFiltAsync",
cacheKey: redisKey,
expiration: TimeSpan.FromMinutes(5),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () =>
await dbController.MacchineGetFiltAsync(codGruppo)
?? new List<MacchineModel>(),
@@ -1513,7 +1513,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "MacchineWithFluxAsync",
cacheKey: currKey,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.MacchineWithFluxAsync(dtStart, dtEnd) ?? new List<string>(),
tagList: [Utils.redisMacByFlux]
);
@@ -1526,7 +1526,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "MachineWithOdlAsync",
cacheKey: redisKey,
expiration: TimeSpan.FromSeconds(3),
expiration: getRandTOut(redisShortTimeCache),
fetchFunc: async () =>
{
var rawData = await dbController.OdlGetCurrentAsync();
@@ -2060,7 +2060,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "POdlListGetFiltAsync",
cacheKey: currKey,
expiration: TimeSpan.FromSeconds(redisShortTimeCache),
expiration: getRandTOut(redisShortTimeCache),
fetchFunc: async () => await dbController.ListPODLFiltAsync(lanciato, keyRichPart, idxMacchina, codGruppo, startDate, endDate) ?? new List<PODLExpModel>(),
tagList: [Utils.redisPOdlList]
);
@@ -2083,7 +2083,7 @@ namespace MP.SPEC.Data
return await GetOrFetchAsync(
operationName: "POdlToKitListGetFiltAsync",
cacheKey: redisKey,
expiration: TimeSpan.FromSeconds(redisShortTimeCache * 5),
expiration: getRandTOut(redisShortTimeCache * 5),
fetchFunc: async () =>
await dbController.ListPODL_KitFiltAsync(
lanciato,
@@ -2369,7 +2369,7 @@ namespace MP.SPEC.Data
var result = await GetOrFetchAsync(
operationName: "TemplateKitFiltAsync",
cacheKey: currKey,
expiration: TimeSpan.FromSeconds(redisLongTimeCache),
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.TemplateKitFiltAsync(codParent, codChild) ?? new List<TemplateKitModel>(),
tagList: [Utils.redisKitTempl]
);
@@ -2595,14 +2595,15 @@ namespace MP.SPEC.Data
#region Protected Methods
/// <summary>
/// Restituisce un timeout dal valore secondi richiesti + tempo random -10..+10 sec
/// Restituisce un timeout dal valore secondi richiesti + tempo random +/-3%
/// </summary>
/// <param name="durationSec"></param>
/// <returns></returns>
protected TimeSpan getRandTOut(double durationSec)
{
double rndValue = durationSec + (double)rand.Next(-5, 5);
return TimeSpan.FromSeconds(rndValue);
double noise = (rand.NextDouble() * 0.06) - 0.03;
double rValue = durationSec * (1 + noise);
return TimeSpan.FromSeconds(rValue);
}
/// <summary>