diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 908adf2a..8d061509 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), @@ -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(), 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(), 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(), tagList: [Utils.redisKitTempl] ); @@ -2595,14 +2595,15 @@ namespace MP.SPEC.Data #region Protected Methods /// - /// Restituisce un timeout dal valore secondi richiesti + tempo random -10..+10 sec + /// Restituisce un timeout dal valore secondi richiesti + tempo random +/-3% /// /// /// 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); } ///