Update cache su altri metodi
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>8.16.2605.2811</Version>
|
||||
<Version>8.16.2605.2812</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-IOC </i>
|
||||
<h4>Versione: 8.16.2605.2811</h4>
|
||||
<h4>Versione: 8.16.2605.2812</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2605.2811
|
||||
8.16.2605.2812
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2605.2811</version>
|
||||
<version>8.16.2605.2812</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>
|
||||
|
||||
@@ -1948,44 +1948,14 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public async Task<PODLModel> POdlGetByOdlAsync(int idxODL)
|
||||
{
|
||||
PODLModel result = new PODLModel();
|
||||
if (idxODL != 0)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("POdlGetByOdlAsync");
|
||||
string source = "DB";
|
||||
string currKey = $"{Utils.redisPOdlByOdl}:{idxODL}";
|
||||
// cerco in redis dato valore sel idxMaccSel...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
var rawResult = JsonConvert.DeserializeObject<PODLModel>($"{rawData}");
|
||||
if (rawResult != null)
|
||||
{
|
||||
result = rawResult;
|
||||
}
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await dbController.PODL_getByOdlAsync(idxODL);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new PODLModel();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.SetTag("result.count", 1);
|
||||
activity?.Stop();
|
||||
Log.Trace($"POdlGetByOdlAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug("Errore IdxODL = 0");
|
||||
}
|
||||
return result;
|
||||
string currKey = $"{Utils.redisPOdlByOdl}:{idxODL}";
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "POdlGetByOdlAsync",
|
||||
cacheKey: currKey,
|
||||
expiration: TimeSpan.FromMinutes(redisLongTimeCache),
|
||||
fetchFunc: async () => await dbController.PODL_getByOdlAsync(idxODL) ?? new(),
|
||||
tagList: [Utils.redisPOdlByOdl]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2411,33 +2381,24 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public async Task<List<TksScoreModel>> TksScoreAsync(string KeyFilt, int MaxResult, bool ForceDb)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("TksScoreAsync");
|
||||
string source = "DB";
|
||||
List<TksScoreModel>? result = new List<TksScoreModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{Utils.redisKitScore}:{KeyFilt}:{MaxResult}";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue && !ForceDb)
|
||||
|
||||
if (ForceDb)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<TksScoreModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
// Se ForceDb è true, saltiamo il GetOrFetchAsync per forzare il fetch dal DB
|
||||
// e aggiornare la cache.
|
||||
var result = await dbController.TksScoreAsync(KeyFilt, MaxResult) ?? new List<TksScoreModel>();
|
||||
await _cache.SetAsync(currKey, result, TimeSpan.FromMinutes(redisLongTimeCache), tags: [Utils.redisKitScore]);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await dbController.TksScoreAsync(KeyFilt, MaxResult);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromSeconds(redisLongTimeCache));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<TksScoreModel>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.SetTag("result.count", result.Count);
|
||||
activity?.Stop();
|
||||
LogTrace($"TksScoreAsync | {source} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "TksScoreAsync",
|
||||
cacheKey: currKey,
|
||||
expiration: TimeSpan.FromMinutes(redisLongTimeCache),
|
||||
fetchFunc: async () => await dbController.TksScoreAsync(KeyFilt, MaxResult) ?? new List<TksScoreModel>(),
|
||||
tagList: [Utils.redisKitScore]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2542,33 +2503,14 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public async Task<List<WipSetupKitModel>> WipKitFiltAsync(string KeyFilt)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("WipKitFiltAsync");
|
||||
string source = "DB";
|
||||
List<WipSetupKitModel>? result = new List<WipSetupKitModel>();
|
||||
// cerco in redis...
|
||||
string currKey = $"{Utils.redisKitWip}:{KeyFilt}";
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<WipSetupKitModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await dbController.WipKitFiltAsync(KeyFilt);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromSeconds(redisLongTimeCache));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<WipSetupKitModel>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.SetTag("result.count", result.Count);
|
||||
activity?.Stop();
|
||||
LogTrace($"WipKitFiltAsync | {source} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "WipKitFiltAsync",
|
||||
cacheKey: currKey,
|
||||
expiration: TimeSpan.FromMinutes(redisLongTimeCache),
|
||||
fetchFunc: async () => await dbController.WipKitFiltAsync(KeyFilt) ?? new List<WipSetupKitModel>(),
|
||||
tagList: [Utils.redisKitWip]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user