diff --git a/MP.Data/Services/BaseServ.cs b/MP.Data/Services/BaseServ.cs index df5344c6..2ca02528 100644 --- a/MP.Data/Services/BaseServ.cs +++ b/MP.Data/Services/BaseServ.cs @@ -368,8 +368,8 @@ namespace MP.Data.Services var cacheOptions = new FusionCacheEntryOptions() .SetDuration(expiration) .SetFailSafe(true); - // cache in RAM per 1/3 del tempo x risparmiare risorse - cacheOptions.MemoryCacheDuration = expiration / 3; + // cache in RAM per 1/2 del tempo x risparmiare risorse + cacheOptions.MemoryCacheDuration = expiration / 2; var final = await _cache.GetOrSetAsync( cacheKey, diff --git a/MP.Data/Services/IOC/IocService.cs b/MP.Data/Services/IOC/IocService.cs index f4901fb0..2595f6cf 100644 --- a/MP.Data/Services/IOC/IocService.cs +++ b/MP.Data/Services/IOC/IocService.cs @@ -91,6 +91,19 @@ namespace MP.Data.Services.IOC /// public async Task GetCurrOdlAsync(string idxMacchina) { + string cKey = $"{MP.Data.Utils.redisOdlCurrByMac}:{idxMacchina}"; + return await GetOrFetchAsync( + operationName: "GetCurrOdlAsync", + cacheKey: cKey, + fetchFunc: async () => + { + return await GetCurrOdlByProdAsync(idxMacchina); + }, + expiration: GetRandTOut(redisShortTimeCache), + tagList: ["IOC_CurrOdl", cKey, idxMacchina] + ); + +#if false string result = ""; string currKey = $"{MP.Data.Utils.redisOdlCurrByMac}:{idxMacchina}"; // cerco in redis dato valOut sel macchina... @@ -104,7 +117,8 @@ namespace MP.Data.Services.IOC result = await GetCurrOdlByProdAsync(idxMacchina); _redisDb.StringSet(currKey, result, GetRandTOut(redisShortTimeCache)); } - return result; + return result; +#endif } /// @@ -117,39 +131,27 @@ namespace MP.Data.Services.IOC /// public async Task IobInsEnabAsync(string idxMacchina) { -#if false - string cacheKey = $"IOC_IobInsEnab_{idxMacchina}"; - return await GetOrFetchAsync(cacheKey, async () => - { - var rKey = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS); - - string? val = await _redisDb.HashGetAsync(rKey, "insEnabled"); - - if (val == null) + string cKey = $"IOC_IobInsEnab_{idxMacchina}"; + return await GetOrFetchAsync( + operationName: "StatoProdMacchinaAsync", + cacheKey: cKey, + fetchFunc: async () => { - var data = await ResetDatiMacchinaAsync(idxMacchina); - data.TryGetValue("insEnabled", out val); - } + var rKey = MP.Data.Utils.RedKeyDatiMacc(idxMacchina, MpIoNS); - return val != null && (val == "1" || val.ToLower() == "true"); - }, TimeSpan.FromSeconds(5)); -#endif + string? val = await _redisDb.HashGetAsync(rKey, "insEnabled"); - 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"); - } + if (val == null) + { + var data = await ResetDatiMacchinaAsync(idxMacchina); + data.TryGetValue("insEnabled", out val); + } - // provo conversione - bool.TryParse($"{rawData}", out answ); - return answ; + return val != null && (val == "1" || val.ToLower() == "true"); + }, + expiration: GetRandTOut(30), + tagList: ["IOC_IobInsEnab", cKey, idxMacchina] + ); } /// @@ -886,6 +888,8 @@ namespace MP.Data.Services.IOC // Eseguiamo tutto in un unico viaggio verso Redis bool success = await transaction.ExecuteAsync(); + await ForceFlushFusionCacheAsync(idxMacc); + return result; } @@ -1040,13 +1044,13 @@ namespace MP.Data.Services.IOC /// private async Task StatoProdMacchinaAsync(string idxMacchina, DateTime dtReq, bool forceDb = false) { - string cKey = $"IOC_StatoProd_{idxMacchina}"; - var stdTTL = TimeSpan.FromSeconds(30); + string cKey = $"{MP.Data.Utils.redisStatoProd}:{idxMacchina}:{dtReq:HHmm}"; return await GetOrFetchAsync( operationName: "StatoProdMacchinaAsync", cacheKey: cKey, fetchFunc: async () => { +#if false StatoProdModel? result = new StatoProdModel(); // cerco in _redisConn... string currKey = $"{MP.Data.Utils.redisStatoProd}:{idxMacchina}:{dtReq:HHmm}"; @@ -1066,9 +1070,11 @@ namespace MP.Data.Services.IOC { result = new StatoProdModel(); } - return result; + return result; +#endif + return await _repo.StatoProdMacchinaAsync(idxMacchina, dtReq); }, - expiration: stdTTL, + expiration: GetRandTOut(30), tagList: ["IOC_StatoProd", cKey, idxMacchina] ); } diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 46403a15..fc29050c 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 8.16.2606.1117 + 8.16.2606.1118 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index 6e78a542..399acdde 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 8.16.2606.1117

+

Versione: 8.16.2606.1118


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index cb037420..edaf8e76 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2606.1117 +8.16.2606.1118 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 02fc9a9e..25228fab 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2606.1117 + 8.16.2606.1118 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 diff --git a/MP.RIOC/Services/MetricsDbFlushService.cs b/MP.RIOC/Services/MetricsDbFlushService.cs index 8a4c2a33..3d89e907 100644 --- a/MP.RIOC/Services/MetricsDbFlushService.cs +++ b/MP.RIOC/Services/MetricsDbFlushService.cs @@ -165,9 +165,19 @@ namespace MP.RIOC.Services var sKey = (RedisKey)$"{statKey}"; if (!TryParseKeyMetadata(sKey, out var meta) || meta.IsHourType) continue; - // Verifica se la chiave è "orfana" (nessun TTL o TTL troppo lungo >30gg) + // Verifica se la chiave è "orfana" + bool isOrphanKey = false; var keyTtl = GetKeyTtl(sKey); - bool isOrphanKey = keyTtl?.TotalSeconds < 0 || keyTtl?.TotalHours > 30.25 * 24; + if (keyTtl == null) + { + // Nessun TTL recuperato = chiave senza scadenza = orfana se > 30 gg + DateTime cutoffDay = DateTime.Today.AddDays(-30); + isOrphanKey = meta.Timestamp < cutoffDay; + } + else + { + isOrphanKey = keyTtl.Value.TotalSeconds < 0 || keyTtl.Value.TotalHours > 30.25 * 24; + } // Se era scaduta o orfana e abbiamo il permesso, segnamola per la cancellazione if ((meta.Timestamp < currentDayStart || isOrphanKey) && deleteConfirmed) @@ -299,9 +309,19 @@ namespace MP.RIOC.Services var sKey = (RedisKey)$"{statKey}"; if (!TryParseKeyMetadata(sKey, out var meta) || !meta.IsHourType) continue; - // Verifica se la chiave è "orfana" (nessun TTL o TTL troppo lungo >15gg) + // Verifica se la chiave è "orfana" + bool isOrphanKey = false; var keyTtl = GetKeyTtl(sKey); - bool isOrphanKey = keyTtl?.TotalSeconds < 0 || keyTtl?.TotalHours > 15.25 * 24; + if (keyTtl == null) + { + // Nessun TTL recuperato = chiave senza scadenza = orfana se > 7 gg + DateTime cutoffHour = DateTime.Now.AddDays(-7); + isOrphanKey = meta.Timestamp < cutoffHour; + } + else + { + isOrphanKey = keyTtl.Value.TotalSeconds < 0 || keyTtl.Value.TotalHours > 15.25 * 24; + } // Se era scaduta o orfana e abbiamo il permesso, segnamola per la cancellazione if ((meta.Timestamp < currentHourStart || isOrphanKey) && deleteConfirmed)