From 5042b41d2e682b4daa889eec4a6e20f7e541482d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 10 Nov 2021 08:46:58 +0100 Subject: [PATCH 1/3] Fix periodo random x valori in cache redis --- GPW_Data/licenzeGPW.cs | 49 ++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/GPW_Data/licenzeGPW.cs b/GPW_Data/licenzeGPW.cs index 504ec1a..73fa8a2 100644 --- a/GPW_Data/licenzeGPW.cs +++ b/GPW_Data/licenzeGPW.cs @@ -1,16 +1,15 @@ -using SteamWare; -using System; +using Newtonsoft.Json; using RestSharp; -using RestSharp.Authenticators; -using System.Threading.Tasks; -using Newtonsoft.Json; +using SteamWare; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; using System.Web; using static GPW_data.LiManObj; -using System.Text; -using System.Security.Cryptography; -using System.Diagnostics; namespace GPW_data { @@ -24,20 +23,37 @@ namespace GPW_data //protected static string apiUrl = "https://localhost:44351/"; protected static string apiUrl = "https://liman.egalware.com/ELM.API/"; - /// - /// Durata cache statica locale dati licenza - /// protected static int LicCacheTTL = 60 * 60 * 24 * 7; - /// - protected static int LicCacheTTL = 120; - protected static string rkeyActInfo = memLayer.ML.redHash($"LiMan:ActInfo"); + protected static string rkeyAppInfo = memLayer.ML.redHash($"LiMan:AppInfo"); + protected static string rkeyLicInfo = memLayer.ML.redHash($"LiMan:LicInfo"); + protected static string rkeyPayload = memLayer.ML.redHash($"LiMan:Payload"); + protected static string rkeyVetoRefPayL = memLayer.ML.redHash($"LiMan:VetoRefPayL"); #endregion Protected Fields + #region Protected Properties + + /// + /// Durata cache statica locale dati licenza, random tra 1 e 2 h + /// protected static int LicCacheTTL = 60 * 60 * 24 * 7; + /// + protected static int LicCacheTTL + { + get + { + Random rndGen = new Random(); + int minVal = 2; + int maxVal = 5; + return rndGen.Next(minVal, maxVal) * 60; + } + } + + #endregion Protected Properties + #region Public Properties /// @@ -132,6 +148,7 @@ namespace GPW_data var okAct = RefreshLicInfo().Result; var okPld = RefreshPayload().Result; + // evito ricalcolo x 5 sec... memLayer.ML.setRSV(rkeyVetoRefPayL, "Veto", 5); sw.Stop(); logger.lg.scriviLog($"Trovato payload non valido, effettuato reset variabili in {sw.ElapsedMilliseconds} ms"); @@ -369,7 +386,7 @@ namespace GPW_data if (string.IsNullOrEmpty(currPayload)) { currPayload = calcPayload(); - memLayer.ML.setRSV(rkeyPayload, currPayload, 3600); + memLayer.ML.setRSV(rkeyPayload, currPayload, LicCacheTTL); } // confronto payload calc con quello della licenza answ = InfoApplicativo.Payload == currPayload; @@ -586,7 +603,7 @@ namespace GPW_data public static async Task RefreshPayload() { bool answ = false; - // svuoto payload calcolato in primis... + // svuoto payload calcolato in primis (ttl a 1 sec)... memLayer.ML.setRSV(rkeyPayload, "", 1); // cerco online From 4619f7d50f08dcd5056474185054105c18f6b0d5 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 10 Nov 2021 08:48:24 +0100 Subject: [PATCH 2/3] Fix TTL tra 2-3 h --- GPW_Data/licenzeGPW.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/GPW_Data/licenzeGPW.cs b/GPW_Data/licenzeGPW.cs index 73fa8a2..29ea034 100644 --- a/GPW_Data/licenzeGPW.cs +++ b/GPW_Data/licenzeGPW.cs @@ -38,16 +38,15 @@ namespace GPW_data #region Protected Properties /// - /// Durata cache statica locale dati licenza, random tra 1 e 2 h - /// protected static int LicCacheTTL = 60 * 60 * 24 * 7; + /// Durata cache statica locale dati licenza, random tra 2/3 h /// protected static int LicCacheTTL { get { Random rndGen = new Random(); - int minVal = 2; - int maxVal = 5; + int minVal = 120; + int maxVal = 180; return rndGen.Next(minVal, maxVal) * 60; } } From 0e59d1ba44b9a708cb72bddbfd26d08e0ae82d8f Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 10 Nov 2021 08:55:26 +0100 Subject: [PATCH 3/3] cambio periodo TTL (circa 1h) --- GPW_Data/licenzeGPW.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GPW_Data/licenzeGPW.cs b/GPW_Data/licenzeGPW.cs index 29ea034..130f79a 100644 --- a/GPW_Data/licenzeGPW.cs +++ b/GPW_Data/licenzeGPW.cs @@ -38,15 +38,15 @@ namespace GPW_data #region Protected Properties /// - /// Durata cache statica locale dati licenza, random tra 2/3 h + /// Durata cache statica locale dati licenza, random circa 1 h /// protected static int LicCacheTTL { get { Random rndGen = new Random(); - int minVal = 120; - int maxVal = 180; + int minVal = 50; + int maxVal = 70; return rndGen.Next(minVal, maxVal) * 60; } }