diff --git a/MP.SPEC/Components/ParamsFilter.razor.cs b/MP.SPEC/Components/ParamsFilter.razor.cs index 05e20d8e..ed1ef126 100644 --- a/MP.SPEC/Components/ParamsFilter.razor.cs +++ b/MP.SPEC/Components/ParamsFilter.razor.cs @@ -41,7 +41,7 @@ namespace MP.SPEC.Components } [Inject] - protected MpDataService MDService { get; set; } + protected MpDataService MDService { get; set; } = null!; protected string selFlux { diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 6c8a4c5c..2c864fec 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -80,7 +80,7 @@ namespace MP.SPEC.Data result = await Task.FromResult(dbController.AnagStatiComm()); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(redisStatoCom, rawData, TimeSpan.FromMinutes(maxAgeConfig)); + await redisDb.StringSetAsync(redisStatoCom, rawData, getRandTOut(maxAgeConfig)); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Debug($"AnagStatiComm Read from DB: {ts.TotalMilliseconds}ms"); @@ -112,7 +112,7 @@ namespace MP.SPEC.Data result = await Task.FromResult(dbController.AnagTipoArtLV()); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(redisTipoArt, rawData, TimeSpan.FromMinutes(maxAgeConfig)); + await redisDb.StringSetAsync(redisTipoArt, rawData, getRandTOut(maxAgeConfig)); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Debug($"AnagTipoArtLV Read from DB: {ts.TotalMilliseconds}ms"); @@ -167,7 +167,7 @@ namespace MP.SPEC.Data string codArticolo = $"{CodArt}"; int cacheCheckArtUsato = 1; int.TryParse(_configuration.GetValue("ServerConf:cacheCheckArtUsato"), out cacheCheckArtUsato); - TimeSpan TTLCache = TimeSpan.FromMinutes(cacheCheckArtUsato); + TimeSpan TTLCache = getRandTOut(cacheCheckArtUsato); // cerco in cache redis... string redKeyArtUsed = $"{Utils.redKeyArtUsed}:{codArticolo}"; string redKeyTabCheckArt = Utils.redKeyTabCheckArt; @@ -242,7 +242,7 @@ namespace MP.SPEC.Data result = await Task.FromResult(dbController.ConfigGetAll()); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(redisConfKey, rawData, TimeSpan.FromMinutes(maxAgeConfig)); + await redisDb.StringSetAsync(redisConfKey, rawData, getRandTOut(maxAgeConfig)); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Debug($"ConfigGetAll Read from DB: {ts.TotalMilliseconds}ms"); @@ -394,7 +394,7 @@ namespace MP.SPEC.Data result = await Task.FromResult(dbController.MacchineGetAll()); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); - redisDb.StringSet(currKey, rawData, TimeSpan.FromMinutes(maxAgeMin)); + redisDb.StringSet(currKey, rawData, getRandTOut(maxAgeMin)); } if (result == null) { @@ -431,7 +431,7 @@ namespace MP.SPEC.Data result = await Task.FromResult(dbController.MacchineWithFlux()); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); - redisDb.StringSet(currKey, rawData, TimeSpan.FromMinutes(maxAgeMin)); + redisDb.StringSet(currKey, rawData, getRandTOut(maxAgeMin)); } if (result == null) { @@ -469,7 +469,7 @@ namespace MP.SPEC.Data result = await Task.FromResult(dbController.ParametriGetFilt(IdxMacchina)); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); - redisDb.StringSet(currKey, rawData, TimeSpan.FromMinutes(maxAgeMin)); + redisDb.StringSet(currKey, rawData, getRandTOut(maxAgeMin)); } if (result == null) { @@ -503,6 +503,27 @@ namespace MP.SPEC.Data #endregion Public Methods + #region Protected Fields + + protected Random rand = new Random(); + + #endregion Protected Fields + + #region Protected Methods + + /// + /// Restituisce un timeout dai minuti richiesti + tempo random 1..60 sec + /// + /// + /// + protected TimeSpan getRandTOut(int stdMinutes) + { + double rndValue = (double)stdMinutes + (double)rand.Next(1, 60) / 60; + return TimeSpan.FromMinutes(rndValue); + } + + #endregion Protected Methods + #region Private Fields private const string redisConfKey = "MP:SPEC:Cache:Config";