From 7a2eab03f4e0a7333ae4c8fc9d08ff800ab60ca7 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 9 Jun 2026 19:26:39 +0200 Subject: [PATCH] update cache timeout vari --- MP.Data/Services/IOC/IocService.cs | 58 +++++++++++++++++------------ MP.IOC/Controllers/IOBController.cs | 1 - MP.IOC/MP.IOC.csproj | 2 +- MP.IOC/Resources/ChangeLog.html | 2 +- MP.IOC/Resources/VersNum.txt | 2 +- MP.IOC/Resources/manifest.xml | 2 +- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/MP.Data/Services/IOC/IocService.cs b/MP.Data/Services/IOC/IocService.cs index 0a709a30..18dfe0b8 100644 --- a/MP.Data/Services/IOC/IocService.cs +++ b/MP.Data/Services/IOC/IocService.cs @@ -81,7 +81,7 @@ namespace MP.Data.Services.IOC result = await GetCurrOdlByProdAsync(idxMacchina); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); - _redisDb.StringSet(currKey, rawData, GetRandTOut(redisLongTimeCache)); + _redisDb.StringSet(currKey, rawData, GetRandTOut(redisLongTimeCache * 2)); } return result; } @@ -96,12 +96,13 @@ namespace MP.Data.Services.IOC /// public async Task IobInsEnabAsync(string idxMacchina) { +#if false string cacheKey = $"IOC_IobInsEnab_{idxMacchina}"; return await GetOrFetchAsync(cacheKey, async () => { - var key = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS); + var rKey = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS); - string? val = await _redisDb.HashGetAsync(key, "insEnabled"); + string? val = await _redisDb.HashGetAsync(rKey, "insEnabled"); if (val == null) { @@ -110,7 +111,25 @@ namespace MP.Data.Services.IOC } return val != null && (val == "1" || val.ToLower() == "true"); - }, TimeSpan.FromSeconds(5)); + }, TimeSpan.FromSeconds(5)); +#endif + + bool answ = false; + // ORA recupero da memoria redis... + var rKey = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS); + RedisValue rawData = await _redisDb.HashGetAsync(rKey, (RedisValue)"insEnabled"); + // se è vuoto... leggo da DB e popolo! + if (!rawData.HasValue) + { + await ResetDatiMacchinaAsync(idxMacchina); + // riprovo + rawData = await _redisDb.HashGetAsync(rKey, (RedisValue)"insEnabled"); + } + + // provo conversione + bool.TryParse($"{rawData}", out answ); + return answ; + } /// @@ -493,25 +512,18 @@ namespace MP.Data.Services.IOC { bool answ = false; // ORA recupero da memoria redis... - try + var rKey = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS); + RedisValue rawData = await _redisDb.HashGetAsync(rKey, (RedisValue)"sLogEnabled"); + // se è vuoto... leggo da DB e popolo! + if (!rawData.HasValue) { - var currHash = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS); - RedisValue rawData = await _redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled"); - // se è vuoto... leggo da DB e popolo! - if (!rawData.HasValue) - { - await ResetDatiMacchinaAsync(idxMacchina); - // riprovo - rawData = await _redisDb.HashGetAsync(currHash, (RedisValue)"sLogEnabled"); - } + await ResetDatiMacchinaAsync(idxMacchina); + // riprovo + rawData = await _redisDb.HashGetAsync(rKey, (RedisValue)"sLogEnabled"); + } - // provo conversione - bool.TryParse($"{rawData}", out answ); - } - catch (Exception exc) - { - Log.Error($"Errore IobSLogEnabAsync | idxMacchina {idxMacchina}:{Environment.NewLine}{exc}"); - } + // provo conversione + bool.TryParse($"{rawData}", out answ); return answ; } @@ -832,7 +844,7 @@ namespace MP.Data.Services.IOC result.Add("palletChange", $"{dbResult.PalletChange}"); // durata cache in secondi dal valOut insEnabled... //double numSecCache = ((result["insEnabled"].ToLower() == "true") ? redisShortTimeCache : redisLongTimeCache); - numSecCache = dbResult.InsEnabled ? redisShortTimeCache : redisLongTimeCache; + numSecCache = dbResult.InsEnabled ? redisShortTimeCache * 2 : redisLongTimeCache; } // dati master/slave @@ -853,7 +865,7 @@ namespace MP.Data.Services.IOC // 3. Inseriamo i nuovi valori _ = transaction.HashSetAsync(redKey, entries); // 4. Impostiamo l'expiration in un unico colpo - _ = transaction.KeyExpireAsync(redKey, TimeSpan.FromSeconds(numSecCache)); + _ = transaction.KeyExpireAsync(redKey, GetRandTOut(numSecCache)); // Eseguiamo tutto in un unico viaggio verso Redis bool success = await transaction.ExecuteAsync(); diff --git a/MP.IOC/Controllers/IOBController.cs b/MP.IOC/Controllers/IOBController.cs index 7a5ff915..bed869a8 100644 --- a/MP.IOC/Controllers/IOBController.cs +++ b/MP.IOC/Controllers/IOBController.cs @@ -479,7 +479,6 @@ namespace MP.IOC.Controllers try { var odl = await IOCService.GetCurrOdlAsync(id); - //var odl = await DService.GetCurrOdlAsync(id); return Ok($"{odl}"); } catch (Exception exc) diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 1f0befe9..12532363 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 8.16.2606.915 + 8.16.2606.919 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 030f4963..954a74a5 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 8.16.2606.915

+

Versione: 8.16.2606.919


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index dec9978c..e358abe4 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.915 +8.16.2606.919 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 6eb549e9..1102abb9 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.915 + 8.16.2606.919 https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html false