Update con cache REDIS x non chiamare sempre DB

This commit is contained in:
Samuele Locatelli
2022-07-08 19:52:50 +02:00
parent 1a019f1c72
commit 7c28833874
11 changed files with 78 additions and 170 deletions
+2 -2
View File
@@ -18,10 +18,10 @@ namespace MP.Mon.Components
var pUpd = Task.Run(async () =>
{
await Task.Delay(1);
await InvokeAsync(StateHasChanged);
await InvokeAsync(() => StateHasChanged());
});
pUpd.Wait();
Log.Trace($"Elapsed Timer Footer");
//Log.Trace($"Elapsed Timer Footer");
}
public void StartTimer()
+1 -1
View File
@@ -74,7 +74,7 @@ namespace MP.Mon.Components
{
Log.Trace($"Elapsed Timer {CurrRecord?.CodMacchina}");
}
await InvokeAsync(StateHasChanged);
await InvokeAsync(() => StateHasChanged());
}
OldRecord = CurrRecord;
});
+28 -3
View File
@@ -108,19 +108,44 @@ namespace MP.Mon.Data
return outVal;
}
private string redisMseKey = "MP:MON:Cache:MSE";
public Task<List<Macchine>> MacchineGetAll()
{
return Task.FromResult(dbController.MacchineGetAll().ToList());
return Task.FromResult(dbController.MacchineGetAll());
}
public Task<List<MappaStatoExpl>> MseGetAll()
public async Task<List<MappaStatoExpl>> MseGetAll()
{
#if false
var dbResult = dbController.MseGetAll();
if (dbResult == null)
{
dbResult = new List<MappaStatoExpl>();
}
return Task.FromResult(dbResult);
return Task.FromResult(dbResult);
#endif
List<MappaStatoExpl> result = new List<MappaStatoExpl>();
// cerco in redis...
var rawData = await redisDb.StringGetAsync(redisMseKey);
if (!string.IsNullOrEmpty(rawData))
{
Log.Trace("Read from REDIS");
result = JsonConvert.DeserializeObject<List<MappaStatoExpl>>(rawData);
}
else
{
Log.Trace("Read from DB");
result = await Task.FromResult(dbController.MseGetAll());
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
await redisDb.StringSetAsync(redisMseKey, rawData, TimeSpan.FromSeconds(2));
}
if (result == null)
{
result = new List<MappaStatoExpl>();
}
return result;
}
#endregion Public Methods
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>6.15.2207.818</Version>
<Version>6.15.2207.819</Version>
</PropertyGroup>
<ItemGroup>
+43 -43
View File
@@ -8,47 +8,6 @@ namespace MP.Mon.Pages
{
public partial class Index : IDisposable
{
#region Protected Fields
protected bool doAnimate = true;
protected int fastRefreshSec = 10;
protected int keepAliveMin = 1;
protected List<MappaStatoExpl>? ListMSE = null;
protected int maxCol = 4;
protected string showArt = "";
protected int slowRefreshSec = 300;
#endregion Protected Fields
#region Private Fields
private static System.Timers.Timer fastTimer = new System.Timers.Timer(4000);
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private static System.Timers.Timer slowTimer = new System.Timers.Timer(300000);
private List<ConfigModel>? CurrConfig = null;
#endregion Private Fields
#region Protected Properties
protected int fastRefreshMs
{
get => 1000 * fastRefreshSec;
}
[Inject]
protected MpDataService MMDataService { get; set; } = null!;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
protected int slowRefreshMs
{
get => 1000 * slowRefreshSec;
}
#endregion Protected Properties
#region Public Methods
public void Dispose()
@@ -97,6 +56,38 @@ namespace MP.Mon.Pages
#endregion Public Methods
#region Protected Fields
protected bool doAnimate = true;
protected int fastRefreshSec = 10;
protected int keepAliveMin = 1;
protected List<MappaStatoExpl>? ListMSE = null;
protected int maxCol = 4;
protected string showArt = "";
protected int slowRefreshSec = 300;
#endregion Protected Fields
#region Protected Properties
protected int fastRefreshMs
{
get => 1000 * fastRefreshSec;
}
[Inject]
protected MpDataService MMDataService { get; set; } = null!;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
protected int slowRefreshMs
{
get => 1000 * slowRefreshSec;
}
#endregion Protected Properties
#region Protected Methods
/// <summary>
@@ -162,7 +153,8 @@ namespace MP.Mon.Pages
}
/// <summary>
/// Recupera da redis (in una chiamata soltanto) tutti i valori richiesti e compone un dizionario x ottimizzare visualizzazione
/// Recupera da redis (in una chiamata soltanto) tutti i valori richiesti e compone un
/// dizionario x ottimizzare visualizzazione
/// </summary>
/// <param name="codIob"></param>
/// <returns></returns>
@@ -188,6 +180,15 @@ namespace MP.Mon.Pages
#endregion Protected Methods
#region Private Fields
private static System.Timers.Timer fastTimer = new System.Timers.Timer(4000);
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private static System.Timers.Timer slowTimer = new System.Timers.Timer(300000);
private List<ConfigModel>? CurrConfig = null;
#endregion Private Fields
#region Private Methods
private async Task ReloadData()
@@ -203,7 +204,6 @@ namespace MP.Mon.Pages
#else
ListMSE = await MMDataService.MseGetAll();
#endif
}
private async Task setupConf()
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MON MAPO</i>
<h4>Versione: 6.15.2207.818</h4>
<h4>Versione: 6.15.2207.819</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
6.15.2207.818
6.15.2207.819
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.15.2207.818</version>
<version>6.15.2207.819</version>
<url>https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/MP.Mon.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
-39
View File
@@ -1,39 +0,0 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">MP.Mon</a>
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</div>
</nav>
</div>
@code {
private bool collapseNavMenu = true;
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}
-62
View File
@@ -1,62 +0,0 @@
.navbar-toggler {
background-color: rgba(255, 255, 255, 0.1);
}
.top-row {
height: 3.5rem;
background-color: rgba(0,0,0,0.4);
}
.navbar-brand {
font-size: 1.1rem;
}
.oi {
width: 2rem;
font-size: 1.1rem;
vertical-align: text-top;
top: -2px;
}
.nav-item {
font-size: 0.9rem;
padding-bottom: 0.5rem;
}
.nav-item:first-of-type {
padding-top: 1rem;
}
.nav-item:last-of-type {
padding-bottom: 1rem;
}
.nav-item ::deep a {
color: #d7d7d7;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
}
.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.25);
color: white;
}
.nav-item ::deep a:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}
@media (min-width: 641px) {
.navbar-toggler {
display: none;
}
.collapse {
/* Never collapse the sidebar for wide screens */
display: block;
}
}
-16
View File
@@ -1,16 +0,0 @@
<div class="alert alert-secondary mt-4">
<span class="oi oi-pencil me-2" aria-hidden="true"></span>
<strong>@Title</strong>
<span class="text-nowrap">
Please take our
<a target="_blank" class="font-weight-bold link-dark" href="https://go.microsoft.com/fwlink/?linkid=2149017">brief survey</a>
</span>
and tell us what you think.
</div>
@code {
// Demonstrates how a parent component can supply parameters
[Parameter]
public string? Title { get; set; }
}