From 41d3eee204c1135a1c26bff373625e28ea7adec9 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 27 Oct 2023 17:09:00 +0200 Subject: [PATCH] Gestione COMPLETA cache SHL da redis: - su ComLib nuovo metodo - nuove chiavi redis cache x macchina/batch/stati - intercettate tutte le chiamate --- AppData/ComLib.cs | 73 +++++++++++++++++-- NKC_WF/WebUserControls/cmp_ML_ShDet.ascx | 13 +++- .../WebUserControls/cmp_labelsPrint.ascx.cs | 6 ++ .../WebUserControls/cmp_unloadSmart.ascx.cs | 7 +- 4 files changed, 91 insertions(+), 8 deletions(-) diff --git a/AppData/ComLib.cs b/AppData/ComLib.cs index eae69e9..cb6997b 100644 --- a/AppData/ComLib.cs +++ b/AppData/ComLib.cs @@ -872,9 +872,14 @@ namespace AppData } else { + // 2023.10.27 passaggio versione cached +#if false // recupero sheet corrente da Bunk... DataLayer DLMan = new DataLayer(); tabSheets = DLMan.taSHL.getByMLStatus(BatchID, 5, 5, machine); + +#endif + tabSheets = SheetTabGet(machine, BatchID, 5, 5); // salvo in redis setCurrSheetTab(machine, tabSheets); } @@ -1726,14 +1731,17 @@ namespace AppData memLayer.ML.redFlushKey(redCurrBunkTabKey(machine)); } + /// /// resetto curr sheets /// /// public static void resetCurrSheet(string machine = "WRK001") { - // svuoto" + // svuoto sheet speciali memLayer.ML.redFlushKey(redCurrSheetTabKey(machine)); + // svuoto tutti i fogli in cache x LOAD page + memLayer.ML.redFlushKey(redCurrSheetTabKey(machine, -1, 0, 0)); } /// @@ -3085,7 +3093,7 @@ namespace AppData } /// - /// Recupero da redis tab fogli correnti + /// Recupero da redis tab fogli correnti (5:5) /// protected static DS_App.SheetListDataTable getCurrSheetTab(string machine) { @@ -3104,6 +3112,36 @@ namespace AppData return answ; } + /// + /// Recupero dati sheet da Redis/DB + /// + public static DS_App.SheetListDataTable SheetTabGet(string Machine, int BatchId, int StMin, int StMax) + { + DS_App.SheetListDataTable answ = null; + string redKey = redCurrSheetTabKey(Machine, BatchId, StMin, StMax); + string rawData = memLayer.ML.getRSV(redKey); + if (!string.IsNullOrEmpty(rawData)) + { + try + { + // deserializzo... + answ = JsonConvert.DeserializeObject(rawData); + } + catch + { } + } + else + { + // leggo DB + DataLayer DLMan = new DataLayer(); + answ = DLMan.taSHL.getByMLStatus(BatchId, StMin, StMax, Machine); + rawData = JsonConvert.SerializeObject(answ); + // salvo in cache x 30 sec + memLayer.ML.setRSV(redKey, rawData, 30); + } + return answ; + } + /// /// Chiave BATCH corrente su redis /// @@ -3198,6 +3236,27 @@ namespace AppData } return answ; } + /// + /// Chiave sheets correnti su redis + /// + /// + /// BatchId, se fosse <= 0 --> chiave parent utile x reset + /// + /// + /// + protected static string redCurrSheetTabKey(string Machine, int BatchId, int StMin, int StMax) + { + string answ = ""; + if (BatchId > 0) + { + answ = $"{redProdReq}:SheetByMBS:{Machine}:{BatchId}:{StMin}:{StMax}"; + } + else + { + answ = $"{redProdReq}:SheetByMBS:{Machine}"; + } + return answ; + } /// /// Chiave primo bunk su redis @@ -3227,7 +3286,7 @@ namespace AppData protected static void setCurrSheetTab(string machine, DS_App.SheetListDataTable tabella) { string rawData = JsonConvert.SerializeObject(tabella); - // TTL 5 sec + // TTL 2 sec memLayer.ML.setRSV(redCurrSheetTabKey(machine), rawData, 2); } @@ -3252,7 +3311,7 @@ namespace AppData } /// - /// Recupera SHEET da batch e sstati permessi... + /// Recupera PRIMO SHEET da batch e stati permessi... /// /// /// @@ -3266,8 +3325,12 @@ namespace AppData { try { + // 2023.10.27 passaggio versione cached +#if false DataLayer DLMan = new DataLayer(); - var tabSheet = DLMan.taSHL.getByMLStatus(BatchID, minVal, maxVal, machine); + var tabSheet = DLMan.taSHL.getByMLStatus(BatchID, minVal, maxVal, machine); +#endif + var tabSheet = SheetTabGet(machine, BatchID, minVal, maxVal); if (tabSheet.Count > 0) { answ = tabSheet[0].SheetID; diff --git a/NKC_WF/WebUserControls/cmp_ML_ShDet.ascx b/NKC_WF/WebUserControls/cmp_ML_ShDet.ascx index 8003df1..775ecfc 100644 --- a/NKC_WF/WebUserControls/cmp_ML_ShDet.ascx +++ b/NKC_WF/WebUserControls/cmp_ML_ShDet.ascx @@ -80,11 +80,20 @@ - + + + + + + + + + +<%-- - +--%> diff --git a/NKC_WF/WebUserControls/cmp_labelsPrint.ascx.cs b/NKC_WF/WebUserControls/cmp_labelsPrint.ascx.cs index 67af80c..8df3b30 100644 --- a/NKC_WF/WebUserControls/cmp_labelsPrint.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_labelsPrint.ascx.cs @@ -66,9 +66,15 @@ namespace NKC_WF.WebUserControls { if (BatchID > 0) { + // 2023.10.27 passaggio versione cached // FORSE 5/5?!? +#if false DataLayer DLMan = new DataLayer(); var sheetList = DLMan.taSHL.getByMLStatus(BatchID, 3, 5, MachineSel); + +#endif + var sheetList = ComLib.SheetTabGet(MachineSel, BatchID, 3, 5); + if (sheetList.Count > 0) { SheetID = sheetList[0].SheetID; diff --git a/NKC_WF/WebUserControls/cmp_unloadSmart.ascx.cs b/NKC_WF/WebUserControls/cmp_unloadSmart.ascx.cs index ce39ba6..e3f27d4 100644 --- a/NKC_WF/WebUserControls/cmp_unloadSmart.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_unloadSmart.ascx.cs @@ -856,9 +856,14 @@ namespace NKC_WF.WebUserControls { if (BatchId > 0) { + // 2023.10.27 passaggio versione cached // FORSE 5/5?!? +#if false DataLayer DLMan = new DataLayer(); - var sheetList = DLMan.taSHL.getByMLStatus(BatchId, 3, 5, PlaceCodFix); + var sheetList = DLMan.taSHL.getByMLStatus(BatchId, 3, 5, PlaceCodFix); +#endif + + var sheetList = ComLib.SheetTabGet(PlaceCodFix, BatchId, 3, 5); if (sheetList.Count > 0) { SheetID = sheetList[0].SheetID;