From e9fdda348d6e46d6df009542dd6c7fecb2d950f0 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 30 Mar 2023 11:13:46 +0200 Subject: [PATCH] Add flux cache page - ForceReload --- .../Data/WebDoorCreatorService.cs | 680 +++++++++--------- WebDoorCreator.UI/Pages/ForceReload.razor | 3 + WebDoorCreator.UI/Pages/ForceReload.razor.cs | 40 ++ 3 files changed, 365 insertions(+), 358 deletions(-) create mode 100644 WebDoorCreator.UI/Pages/ForceReload.razor create mode 100644 WebDoorCreator.UI/Pages/ForceReload.razor.cs diff --git a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs index 99a36af..e08462b 100644 --- a/WebDoorCreator.UI/Data/WebDoorCreatorService.cs +++ b/WebDoorCreator.UI/Data/WebDoorCreatorService.cs @@ -1,15 +1,13 @@ using EgwCoreLib.Razor.Data; using Microsoft.AspNetCore.Identity.UI.Services; +using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using NLog; using StackExchange.Redis; using System.Diagnostics; +using WebDoorCreator.Core; using WebDoorCreator.Data.Controllers; using WebDoorCreator.Data.DbModels; -using WebDoorCreator.Core; -using System.Security.AccessControl; -using WebDoorCreator.Data; -using Microsoft.EntityFrameworkCore; namespace WebDoorCreator.UI.Data { @@ -62,8 +60,20 @@ namespace WebDoorCreator.UI.Data #region Public Methods - #region Company methods - + /// + /// Update company + /// + /// + /// + public async Task CompanyAddMod(CompanyModel currRec) + { + var dbResult = await dbController.CompanyAddMod(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyCompany}"); + bool answ = await ExecFlushRedisPattern(pattern); + await Task.Delay(1); + return dbResult; + } /// /// Company list filtered by company id @@ -109,104 +119,51 @@ namespace WebDoorCreator.UI.Data return dbResult; } - /// - /// Update company - /// - /// - /// - public async Task CompanyAddMod(CompanyModel currRec) - { - var dbResult = await dbController.CompanyAddMod(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyCompany}"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - - #endregion Company methods - /*----------------------------------------------------------------------------------------------------------------------*/ - #region Cache methods - - /// - /// Esegue flush memoria redis dato pattern - /// - /// - /// - private async Task ExecFlushRedisPattern(RedisValue pattern) - { - bool answ = false; - var listEndpoints = redisConn.GetEndPoints(); - foreach (var endPoint in listEndpoints) - { - //var server = redisConnAdmin.GetServer(listEndpoints[0]); - var server = redisConn.GetServer(endPoint); - if (server != null) - { - var keyList = server.Keys(redisDb.Database, pattern); - foreach (var item in keyList) - { - await redisDb.KeyDeleteAsync(item); - } - answ = true; - } - } - - return answ; - } - - public async Task FlushRedisCache() - { - await Task.Delay(1); - RedisValue pattern = new RedisValue($"{redisBaseAddr}"); - bool answ = await ExecFlushRedisPattern(pattern); - return answ; - } - - #endregion Cache methods - - /*----------------------------------------------------------------------------------------------------------------------*/ - - #region Security Methods - public string DecriptData(string encData) { return SteamCrypto.DecryptString(encData, passPhrase); } - public string EncriptData(string rawData) + /// + /// Adding or removing a single door + /// + /// Record id to edit or add + /// States if it has to be added or removing a door + /// + public async Task DoorModQty(int doorId, bool isAdd) { - return SteamCrypto.EncryptString(rawData, passPhrase); + var dbResult = await dbController.DoorModQty(doorId, isAdd); + // elimino cache redis dati porta... + RedisValue pattern = new RedisValue($"{rKeyDoor}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + // elimino cache redis dati ordine... + pattern = new RedisValue($"{rKeyOrderStatus}:*"); + answ = await ExecFlushRedisPattern(pattern); + return dbResult; } - #endregion Security Methods - - /*----------------------------------------------------------------------------------------------------------------------*/ - - #region User Methods - /// - /// Users roles list + /// Doors list by orderId /// - public async Task?> GetUserView() + public async Task?> DoorsGetByOrderId(int orderId) { string source = "DB"; - List? dbResult = new List(); + List? dbResult = new List(); // cerco da cache - string currKey = rKeyUsersView; + string currKey = $"{rKeyDoor}:{orderId}"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string? rawData = await redisDb.StringGetAsync(currKey); if (!string.IsNullOrEmpty(rawData)) { source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); + var tempResult = JsonConvert.DeserializeObject>(rawData); if (tempResult == null) { - dbResult = new List(); + dbResult = new List(); } else { @@ -215,17 +172,149 @@ namespace WebDoorCreator.UI.Data } else { - dbResult = dbController.GetUserView(); + dbResult = dbController.DoorsGetByOrderId(orderId); rawData = JsonConvert.SerializeObject(dbResult, JSSettings); await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); } if (dbResult == null) { - dbResult = new List(); + dbResult = new List(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"GetUserView | {source} in: {ts.TotalMilliseconds} ms"); + Log.Debug($"DoorsGetByOrderId | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Update or add door + /// + /// + /// + public async Task DoorUpsert(DoorModel currRec) + { + var dbResult = await dbController.DoorUpsert(currRec); + // elimino cache redis dati porta... + RedisValue pattern = new RedisValue($"{rKeyDoor}:{currRec.DoorId}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + // elimino cache redis dati ordine... + answ = answ && await OrdersFlushCache(); + return dbResult; + } + + public string EncriptData(string rawData) + { + return SteamCrypto.EncryptString(rawData, passPhrase); + } + + public async Task FlushRedisCache() + { + await Task.Delay(1); + RedisValue pattern = new RedisValue($"{redisBaseAddr}*"); + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + + /// + /// Getting a list of all the active components + /// + /// Path to start + /// + public async Task> GetAllActiveCompo(string rootPath) + { + await Task.Delay(1); + List listActiveCompo = new List(); + + //estraggo la lista di componenti che sono attive per il cliente + IniFile fIni = new IniFile(rootPath); + string compoDDF = fIni.ReadString("CompoOrder", "CompoDDFOrder", "CONFIG"); + var compoDDFList = compoDDF.Split(","); + foreach (string compo in compoDDFList) + { + listActiveCompo.Add(compo.Trim()); + } + + return listActiveCompo; + } + + public async Task?> GetOrderStatus(int companyId, int orderStatus, DateTime dataFrom, DateTime dataTo) + { + string source = "DB"; + + List? dbResult = new List(); + // cerco da cache + string currKey = $"{rKeyOrderStatus}:{companyId}:{orderStatus}:{dataFrom:yyyyMMdd}:{dataTo:yyyyMMdd}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.GetOrderStatus(companyId, orderStatus, dataFrom, dataTo); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"GetOrderStatus | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// roles list + /// + public async Task?> GetRolesAll() + { + string source = "DB"; + + List? dbResult = new List(); + // cerco da cache + string currKey = rKeyRoles; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.GetRolesAll(); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"GetRolesAll | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } @@ -313,32 +402,26 @@ namespace WebDoorCreator.UI.Data return dbResult; } - #endregion User Methods - - /*----------------------------------------------------------------------------------------------------------------------*/ - - #region Roles Methods - /// - /// roles list + /// Users roles list /// - public async Task?> GetRolesAll() + public async Task?> GetUserView() { string source = "DB"; - List? dbResult = new List(); + List? dbResult = new List(); // cerco da cache - string currKey = rKeyRoles; + string currKey = rKeyUsersView; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string? rawData = await redisDb.StringGetAsync(currKey); if (!string.IsNullOrEmpty(rawData)) { source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); + var tempResult = JsonConvert.DeserializeObject>(rawData); if (tempResult == null) { - dbResult = new List(); + dbResult = new List(); } else { @@ -347,177 +430,20 @@ namespace WebDoorCreator.UI.Data } else { - dbResult = dbController.GetRolesAll(); + dbResult = dbController.GetUserView(); rawData = JsonConvert.SerializeObject(dbResult, JSSettings); await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); } if (dbResult == null) { - dbResult = new List(); + dbResult = new List(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"GetRolesAll | {source} in: {ts.TotalMilliseconds} ms"); + Log.Debug($"GetUserView | {source} in: {ts.TotalMilliseconds} ms"); return dbResult; } - #endregion Roles Methods - - /*----------------------------------------------------------------------------------------------------------------------*/ - - #region Order status Methods - - public async Task?> GetOrderStatus(int companyId, int orderStatus, DateTime dataFrom, DateTime dataTo) - { - string source = "DB"; - - List? dbResult = new List(); - // cerco da cache - string currKey = $"{rKeyOrderStatus}:{companyId}:{orderStatus}:{dataFrom:yyyyMMdd}:{dataTo:yyyyMMdd}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.GetOrderStatus(companyId, orderStatus, dataFrom, dataTo); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - } - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"GetOrderStatus | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - #endregion Order status Methods - - /*----------------------------------------------------------------------------------------------------------------------*/ - - #region Order Methods - - /// - /// Add new order - /// - /// - /// - public async Task OrderAdd(OrderModel currRec) - { - var dbResult = await dbController.OrderAdd(currRec); - // elimino cache redis... - RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - - #endregion Order Methods - - /*----------------------------------------------------------------------------------------------------------------------*/ - - #region Door Methods - - /// - /// Doors list by orderId - /// - public async Task?> DoorsGetByOrderId(int orderId) - { - string source = "DB"; - - List? dbResult = new List(); - // cerco da cache - string currKey = $"{rKeyDoor}:{orderId}"; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - string? rawData = await redisDb.StringGetAsync(currKey); - if (!string.IsNullOrEmpty(rawData)) - { - source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); - if (tempResult == null) - { - dbResult = new List(); - } - else - { - dbResult = tempResult; - } - } - else - { - dbResult = dbController.DoorsGetByOrderId(orderId); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - } - if (dbResult == null) - { - dbResult = new List(); - } - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"DoorsGetByOrderId | {source} in: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - /// - /// Update or add door - /// - /// - /// - public async Task DoorUpsert(DoorModel currRec) - { - var dbResult = await dbController.DoorUpsert(currRec); - // elimino cache redis dati porta... - RedisValue pattern = new RedisValue($"{rKeyDoor}:{currRec.DoorId}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - // elimino cache redis dati ordine... - pattern = new RedisValue($"{rKeyOrderStatus}:*"); - answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - - /// - /// Adding or removing a single door - /// - /// Record id to edit or add - /// States if it has to be added or removing a door - /// - public async Task DoorModQty(int doorId, bool isAdd) - { - var dbResult = await dbController.DoorModQty(doorId, isAdd); - // elimino cache redis dati porta... - RedisValue pattern = new RedisValue($"{rKeyDoor}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - // elimino cache redis dati ordine... - pattern = new RedisValue($"{rKeyOrderStatus}:*"); - answ = await ExecFlushRedisPattern(pattern); - await Task.Delay(1); - return dbResult; - } - - #endregion Door Methods - - /*----------------------------------------------------------------------------------------------------------------------*/ - - #region ListValues Methods - /// /// Company list /// @@ -560,88 +486,35 @@ namespace WebDoorCreator.UI.Data return dbResult; } - #endregion ListValues Methods - - /*----------------------------------------------------------------------------------------------------------------------*/ - - #region IniFiles Methods - - /// - /// Getting a list of all the active components + /// Add new order /// - /// Path to start + /// /// - public async Task> GetAllActiveCompo(string rootPath) + public async Task OrderAdd(OrderModel currRec) { + var dbResult = await dbController.OrderAdd(currRec); + // elimino cache redis... + RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*"); + bool answ = await ExecFlushRedisPattern(pattern); await Task.Delay(1); - List listActiveCompo = new List(); - - //estraggo la lista di componenti che sono attive per il cliente - IniFile fIni = new IniFile(rootPath); - string compoDDF = fIni.ReadString("CompoOrder", "CompoDDFOrder", "CONFIG"); - var compoDDFList = compoDDF.Split(","); - foreach (string compo in compoDDFList) - { - listActiveCompo.Add(compo.Trim()); - } - - return listActiveCompo; + return dbResult; } /// - /// Setting the graphic parameters for components + /// Clean redis ORDERS cache /// - /// - /// - /// - /// + /// /// - public async Task> SetGraphicParams(string file, string match, int n, int i) + public async Task OrdersFlushCache() { - await Task.Delay(1); - List listGraphicParams = new List(); - - IniFile fIni = new IniFile(file); - //estraggo la lista di componenti che sono attive per il cliente - var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2)); //cerco il contenuto delle sezioni - if (int.Parse(match.Substring(match.Length - 2, 1)) == n) //controllo se tra i numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti i parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1 - { - foreach (string param in graphicParamsName) - { - string compoParams = fIni.ReadString(match.Substring(1, match.Length - 2), $"{param.Split("=")[0]}", "CONFIG"); //cerco il parametro nella sezione - var compoParamsSplit = compoParams.Split(";"); - - string CompoParamName = ""; - string CompoParamAlias = ""; - if (param.Split("=")[0].StartsWith("Param")) - { - if (compoParamsSplit[1].Contains("/")) - { - CompoParamName = compoParamsSplit[1].Split("/")[0]; - CompoParamAlias = compoParamsSplit[1].Split("/")[1]; - - } - - GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = CompoParamName, graphicParamAlias = CompoParamAlias, graphicParamType = compoParamsSplit[0], graphicParamDefaultVal = compoParamsSplit[2] }; - listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione - await dbController.ParamAdd(graphicParams); - } - else - { - GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = compoParams }; - listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione - await dbController.ParamAdd(graphicParams); - } - } - } - - return listGraphicParams; + RedisValue pattern = new RedisValue($"{rKeyOrderStatus}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + return answ; } - /// - /// Setting all the component list + /// Setting all the component list /// /// Path to start /// @@ -678,7 +551,7 @@ namespace WebDoorCreator.UI.Data { compoTemplateIsActive = false; } - var compoNameSplit = compoName.Split("/"); // lo slash indica l'alias + var compoNameSplit = compoName.Split("/"); // lo slash indica l'alias if (listActiveCompo.Contains(compoNameSplit[0].ToString())) { HardwareModel compoConfig = new HardwareModel() { compoName = compoNameSplit[0].ToString(), compoAlias = compoNameSplit[1].ToString(), compoLayerName = layerName, compoTemplateIsActive = compoTemplateIsActive }; //creo il componente (padre) @@ -707,7 +580,6 @@ namespace WebDoorCreator.UI.Data } i++; } - } List edges = new List(); @@ -753,40 +625,59 @@ namespace WebDoorCreator.UI.Data return fatto; } - #endregion IniFiles Methods + /// + /// Setting the graphic parameters for components + /// + /// + /// + /// + /// + /// + public async Task> SetGraphicParams(string file, string match, int n, int i) + { + await Task.Delay(1); + List listGraphicParams = new List(); + + IniFile fIni = new IniFile(file); + //estraggo la lista di componenti che sono attive per il cliente + var graphicParamsName = fIni.ReadSection(match.Substring(1, match.Length - 2)); //cerco il contenuto delle sezioni + if (int.Parse(match.Substring(match.Length - 2, 1)) == n) //controllo se tra i numeri di graphic params vi è un buco ES: Graphic parameters1 Graphic parameters3 se il buco c'è salto tutti i parametri che stanno dopo il buco ==> tengo conto solo di Graphic parameters1 + { + foreach (string param in graphicParamsName) + { + string compoParams = fIni.ReadString(match.Substring(1, match.Length - 2), $"{param.Split("=")[0]}", "CONFIG"); //cerco il parametro nella sezione + var compoParamsSplit = compoParams.Split(";"); + + string CompoParamName = ""; + string CompoParamAlias = ""; + if (param.Split("=")[0].StartsWith("Param")) + { + if (compoParamsSplit[1].Contains("/")) + { + CompoParamName = compoParamsSplit[1].Split("/")[0]; + CompoParamAlias = compoParamsSplit[1].Split("/")[1]; + } + + GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = CompoParamName, graphicParamAlias = CompoParamAlias, graphicParamType = compoParamsSplit[0], graphicParamDefaultVal = compoParamsSplit[2] }; + listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione + await dbController.ParamAdd(graphicParams); + } + else + { + GraphicParamsModel graphicParams = new GraphicParamsModel() { compoId = i, graphicParamsN = match.Substring(1, match.Length - 2), graphicParamKey = param.Split("=")[0], graphicParamName = compoParams }; + listGraphicParams.Add(graphicParams); //creo nuovo oggetto parametro che conterrà anche il nome del componente per creare relazione + await dbController.ParamAdd(graphicParams); + } + } + } + + return listGraphicParams; + } #endregion Public Methods #region Protected Fields - #region Private Properties - - /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) - /// - private TimeSpan FastCache - { - get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000); - } - - /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) - /// - private TimeSpan LongCache - { - get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000); - } - - /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) - /// - private TimeSpan UltraLongCache - { - get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000); - } - - #endregion Private Properties - protected const string passPhrase = "9eb4660f-8753-46bc-b23b-08759ba03fe9"; //#region Protected Fields @@ -795,13 +686,18 @@ namespace WebDoorCreator.UI.Data //#endregion Public Methods protected const string rKeyCompany = $"{redisBaseAddr}:Cache:Company"; - protected const string rKeyOrderStatus = $"{redisBaseAddr}:Cache:OrderStatus"; - protected const string rKeyUsers = $"{redisBaseAddr}:Cache:Users"; - protected const string rKeyUsersView = $"{redisBaseAddr}:Cache:UsersView"; - protected const string rKeyRoles = $"{redisBaseAddr}:Cache:Roles"; protected const string rKeyDoor = $"{redisBaseAddr}:Cache:Doors"; + protected const string rKeyListValues = $"{redisBaseAddr}:Cache:ListValues"; + protected const string rKeyOrderStatus = $"{redisBaseAddr}:Cache:OrderStatus"; + + protected const string rKeyRoles = $"{redisBaseAddr}:Cache:Roles"; + + protected const string rKeyUsers = $"{redisBaseAddr}:Cache:Users"; + + protected const string rKeyUsersView = $"{redisBaseAddr}:Cache:UsersView"; + protected Random rnd = new Random(); #endregion Protected Fields @@ -838,5 +734,73 @@ namespace WebDoorCreator.UI.Data private IDatabase redisDb = null!; #endregion Private Fields + + #region Private Properties + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan FastCache + { + get => TimeSpan.FromSeconds(cacheTtlShort * rnd.Next(900, 1100) / 1000); + } + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan LongCache + { + get => TimeSpan.FromSeconds(cacheTtlLong * rnd.Next(900, 1100) / 1000); + } + + /// + /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// + private TimeSpan UltraLongCache + { + get => TimeSpan.FromSeconds(cacheTtlLong * 10 * rnd.Next(900, 1100) / 1000); + } + + #endregion Private Properties + + #region Private Methods + + /// + /// Esegue flush memoria redis dato pattern + /// + /// + /// + private async Task ExecFlushRedisPattern(RedisValue pattern) + { + bool answ = false; + var listEndpoints = redisConn.GetEndPoints(); + foreach (var endPoint in listEndpoints) + { + //var server = redisConnAdmin.GetServer(listEndpoints[0]); + var server = redisConn.GetServer(endPoint); + if (server != null) + { + var keyList = server.Keys(redisDb.Database, pattern); + foreach (var item in keyList) + { + await redisDb.KeyDeleteAsync(item); + } + answ = true; + } + } + + return answ; + } + + #endregion Private Methods + + /*----------------------------------------------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------------------------------------------------*/ } } \ No newline at end of file diff --git a/WebDoorCreator.UI/Pages/ForceReload.razor b/WebDoorCreator.UI/Pages/ForceReload.razor new file mode 100644 index 0000000..e45c89e --- /dev/null +++ b/WebDoorCreator.UI/Pages/ForceReload.razor @@ -0,0 +1,3 @@ +@page "/ForceReload" + + diff --git a/WebDoorCreator.UI/Pages/ForceReload.razor.cs b/WebDoorCreator.UI/Pages/ForceReload.razor.cs new file mode 100644 index 0000000..79045d5 --- /dev/null +++ b/WebDoorCreator.UI/Pages/ForceReload.razor.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Components; +using WebDoorCreator.UI.Data; + +namespace WebDoorCreator.UI.Pages +{ + public partial class ForceReload + { + #region Public Methods + + public async Task flushCache() + { + await Task.Delay(1); + await WDService.FlushRedisCache(); + await Task.Delay(1); + // rimando a pagina corrente + NavManager.NavigateTo("/", true); + } + + #endregion Public Methods + + #region Protected Properties + + [Inject] + protected NavigationManager NavManager { get; set; } = null!; + + [Inject] + protected WebDoorCreatorService WDService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected override async Task OnInitializedAsync() + { + await flushCache(); + } + + #endregion Protected Methods + } +} \ No newline at end of file