From 7ca5637fe476c63fee2d9e480ec01edd2c6d9cc4 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 6 May 2026 07:15:57 +0200 Subject: [PATCH] Aggiunta InMemoryCache x servizi legati a INPUT (es list master/slave) --- MP.Data/Services/IOC/IocService.cs | 25 ++++++++++++++++++++++--- MP.IOC/MP.IOC.csproj | 2 +- MP.IOC/Resources/ChangeLog.html | 2 +- MP.IOC/Resources/VersNum.txt | 2 +- MP.IOC/Resources/manifest.xml | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/MP.Data/Services/IOC/IocService.cs b/MP.Data/Services/IOC/IocService.cs index 8c5b9407..f8b03f89 100644 --- a/MP.Data/Services/IOC/IocService.cs +++ b/MP.Data/Services/IOC/IocService.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using MP.Core.Objects; using MP.Data.DbModels; @@ -23,13 +24,15 @@ namespace MP.Data.Services.IOC IConfiguration config, IConnectionMultiplexer redis, IIocRepository repo, - IServiceScopeFactory scopeFactory) : base(config, redis) + IServiceScopeFactory scopeFactory, + Microsoft.Extensions.Caching.Memory.IMemoryCache cache) : base(config, redis) { _className = "IocServ"; int.TryParse(config.GetValue("ServerConf:redisLongTimeCache"), out redisLongTimeCache); int.TryParse(config.GetValue("ServerConf:redisShortTimeCache"), out redisShortTimeCache); _repo = repo; _scopeFactory = scopeFactory; + _cache = cache; } #endregion Public Constructors @@ -176,8 +179,8 @@ namespace MP.Data.Services.IOC private readonly string _className; private readonly IIocRepository _repo; - private readonly IServiceScopeFactory _scopeFactory; + private readonly Microsoft.Extensions.Caching.Memory.IMemoryCache _cache; /// /// Provider CultureInfo x parse valori (es dataora) @@ -387,6 +390,12 @@ namespace MP.Data.Services.IOC private async Task> ListMasterAsync() { + const string cacheKey = "IOC_ListMaster"; + if (_cache.TryGetValue(cacheKey, out HashSet? cachedList)) + { + return cachedList!; + } + HashSet result = new(); string currKey = $"{MP.Data.Utils.redisBaseAddr}:ListMaster"; RedisValue rawData = await _redisDb.StringGetAsync(currKey); @@ -402,11 +411,19 @@ namespace MP.Data.Services.IOC rawData = JsonConvert.SerializeObject(result); await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10)); } + + _cache.Set(cacheKey, result, TimeSpan.FromMinutes(5)); return result; } private async Task> ListSlaveAsync() { + const string cacheKey = "IOC_ListSlave"; + if (_cache.TryGetValue(cacheKey, out HashSet? cachedList)) + { + return cachedList!; + } + HashSet result = new(); string currKey = $"{MP.Data.Utils.redisBaseAddr}:ListSlave"; RedisValue rawData = await _redisDb.StringGetAsync(currKey); @@ -422,6 +439,8 @@ namespace MP.Data.Services.IOC rawData = JsonConvert.SerializeObject(result); await _redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache * 10)); } + + _cache.Set(cacheKey, result, TimeSpan.FromMinutes(5)); return result; } diff --git a/MP.IOC/MP.IOC.csproj b/MP.IOC/MP.IOC.csproj index 09b2a86c..b1c6362a 100644 --- a/MP.IOC/MP.IOC.csproj +++ b/MP.IOC/MP.IOC.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 8.16.2605.415 + 8.16.2605.607 diff --git a/MP.IOC/Resources/ChangeLog.html b/MP.IOC/Resources/ChangeLog.html index e967c5a4..7c872463 100644 --- a/MP.IOC/Resources/ChangeLog.html +++ b/MP.IOC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MP-IOC -

Versione: 8.16.2605.415

+

Versione: 8.16.2605.607


Note di rilascio:
  • diff --git a/MP.IOC/Resources/VersNum.txt b/MP.IOC/Resources/VersNum.txt index c9e2711c..b78c4978 100644 --- a/MP.IOC/Resources/VersNum.txt +++ b/MP.IOC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2605.415 +8.16.2605.607 diff --git a/MP.IOC/Resources/manifest.xml b/MP.IOC/Resources/manifest.xml index 39fb4c88..97a76db6 100644 --- a/MP.IOC/Resources/manifest.xml +++ b/MP.IOC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2605.415 + 8.16.2605.607 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