Aggiunta InMemoryCache x servizi legati a INPUT (es list master/slave)

This commit is contained in:
Samuele Locatelli
2026-05-06 07:15:57 +02:00
parent 5e258917c4
commit 7ca5637fe4
5 changed files with 26 additions and 7 deletions
+22 -3
View File
@@ -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<string>("ServerConf:redisLongTimeCache"), out redisLongTimeCache);
int.TryParse(config.GetValue<string>("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;
/// <summary>
/// Provider CultureInfo x parse valori (es dataora)
@@ -387,6 +390,12 @@ namespace MP.Data.Services.IOC
private async Task<HashSet<string>> ListMasterAsync()
{
const string cacheKey = "IOC_ListMaster";
if (_cache.TryGetValue(cacheKey, out HashSet<string>? cachedList))
{
return cachedList!;
}
HashSet<string> 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<HashSet<string>> ListSlaveAsync()
{
const string cacheKey = "IOC_ListSlave";
if (_cache.TryGetValue(cacheKey, out HashSet<string>? cachedList))
{
return cachedList!;
}
HashSet<string> 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;
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>8.16.2605.415</Version>
<Version>8.16.2605.607</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MP-IOC </i>
<h4>Versione: 8.16.2605.415</h4>
<h4>Versione: 8.16.2605.607</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.415
8.16.2605.607
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.415</version>
<version>8.16.2605.607</version>
<url>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>