Update cache su altri metodi
This commit is contained in:
@@ -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