Fix cleanup
- redis - obj non usati
This commit is contained in:
@@ -257,6 +257,15 @@ namespace MP.Land.Data
|
||||
MpDbController.Dispose();
|
||||
}
|
||||
|
||||
public async Task FlushRedisCache()
|
||||
{
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddr}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
// reset in RAM
|
||||
Vocabolario = new Dictionary<string, string>();
|
||||
CheckVoc();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco permessi dato utente
|
||||
/// </summary>
|
||||
@@ -307,42 +316,6 @@ namespace MP.Land.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task FlushRedisCache()
|
||||
{
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddr}:*");
|
||||
bool answ = await ExecFlushRedisPattern(pattern);
|
||||
// reset in RAM
|
||||
Vocabolario = new Dictionary<string, string>();
|
||||
await CheckVoc();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
/// </summary>
|
||||
/// <param name="pattern"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> ExecFlushRedisPattern(RedisValue pattern)
|
||||
{
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConn.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConn.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
public string Traduci(string lemma, string lingua = "IT")
|
||||
{
|
||||
string answ = $"__{lemma}__";
|
||||
@@ -420,7 +393,7 @@ namespace MP.Land.Data
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected async Task CheckVoc()
|
||||
protected void CheckVoc()
|
||||
{
|
||||
if (Vocabolario.Count == 0)
|
||||
{
|
||||
@@ -428,7 +401,7 @@ namespace MP.Land.Data
|
||||
string currKey = $"{redisBaseAddr}:MP:VOCAB";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
string? rawData = redisDb.StringGet(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData) && rawData.Length > 2)
|
||||
{
|
||||
source = "REDIS";
|
||||
@@ -437,9 +410,11 @@ namespace MP.Land.Data
|
||||
}
|
||||
else
|
||||
{
|
||||
Vocabolario = dbController.VocabolarioGetAll().ToDictionary(x => $"{x.Lingua}#{x.Lemma}", x => x.Traduzione);
|
||||
Vocabolario = dbController
|
||||
.VocabolarioGetAll()
|
||||
.ToDictionary(x => $"{x.Lingua}#{x.Lemma}", x => x.Traduzione);
|
||||
rawData = JsonConvert.SerializeObject(Vocabolario);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
redisDb.StringSet(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
sw.Stop();
|
||||
Log.Trace($"Rilettura Vocabolario | {source} | {sw.ElapsedMilliseconds} ms");
|
||||
@@ -454,11 +429,17 @@ namespace MP.Land.Data
|
||||
private const string redisBaseAddr = "MP:LAND";
|
||||
|
||||
private const string rKeyDirittiUser = $"{redisBaseAddr}:DIR_USER";
|
||||
|
||||
private const string rKeyPermUser = $"{redisBaseAddr}:PERM_USER";
|
||||
|
||||
private static IConfiguration _configuration;
|
||||
|
||||
private static ILogger<AppAuthService> _logger;
|
||||
|
||||
private static List<Macchine> ElencoMacchine = new List<Macchine>();
|
||||
|
||||
private static JsonSerializerSettings? JSSettings;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private static string Modulo = "";
|
||||
@@ -485,6 +466,7 @@ namespace MP.Land.Data
|
||||
private IDatabase redisDb = null!;
|
||||
|
||||
private Random rnd = new Random();
|
||||
|
||||
private Dictionary<string, string> Vocabolario = new Dictionary<string, string>();
|
||||
|
||||
#endregion Private Fields
|
||||
@@ -518,5 +500,36 @@ namespace MP.Land.Data
|
||||
}
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Esegue flush memoria redis dato pattern
|
||||
/// </summary>
|
||||
/// <param name="pattern"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<bool> ExecFlushRedisPattern(RedisValue pattern)
|
||||
{
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConn.GetEndPoints();
|
||||
foreach (var endPoint in listEndpoints)
|
||||
{
|
||||
//var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
var server = redisConn.GetServer(endPoint);
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,6 @@ namespace MP.Land.Data
|
||||
{
|
||||
List<LiManObj.AttivazioneDTO> dbResult = new List<LiManObj.AttivazioneDTO>();
|
||||
string cacheKey = $"{rKeyAttByLic}:{MasterKey}";
|
||||
trackCache(cacheKey);
|
||||
string rawData = await getRSV(cacheKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
@@ -235,7 +234,6 @@ namespace MP.Land.Data
|
||||
{
|
||||
List<LiManObj.ApplicativoDTO> dbResult = new List<LiManObj.ApplicativoDTO>();
|
||||
string cacheKey = $"{rkeyAppInfo}:{MasterKey}";
|
||||
trackCache(cacheKey);
|
||||
string rawData = await getRSV(cacheKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
@@ -404,18 +402,6 @@ namespace MP.Land.Data
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registra in cache chiave se non fosse già in elenco
|
||||
/// </summary>
|
||||
/// <param name="newKey"></param>
|
||||
protected void trackCache(string newKey)
|
||||
{
|
||||
if (!cachedDataList.Contains(newKey))
|
||||
{
|
||||
cachedDataList.Add(newKey);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
@@ -434,21 +420,6 @@ namespace MP.Land.Data
|
||||
/// </summary>
|
||||
private static string rkeyAppInfo = "LongCache:AppInfo";
|
||||
|
||||
/// <summary>
|
||||
/// Elenco obj in cache
|
||||
/// </summary>
|
||||
private List<string> cachedDataList = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache lunga IN SECONDI
|
||||
/// </summary>
|
||||
private int cacheTtlLong = 60 * 5;
|
||||
|
||||
/// <summary>
|
||||
/// Durata cache breve IN SECONDI
|
||||
/// </summary>
|
||||
private int cacheTtlShort = 60 * 1;
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS
|
||||
/// </summary>
|
||||
|
||||
@@ -70,7 +70,6 @@ namespace MP.Land.Shared
|
||||
|
||||
protected bool annualAuthOk { get; set; } = false;
|
||||
|
||||
private List<MP.AppAuth.Models.UpdMan> ListRecords;
|
||||
|
||||
#endregion Private Properties
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace MP.Land.Shared
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private async Task checkAuth()
|
||||
private void checkAuth()
|
||||
{
|
||||
// verifico pagina tra i permessi, se manca --> rimando a pagina unauth... se contiene
|
||||
// index --> salto
|
||||
@@ -133,7 +133,7 @@ namespace MP.Land.Shared
|
||||
UserRight = await DataService.DirittiGetByUser(uName);
|
||||
UserPerm = await DataService.PermessiGetByUser(uName);
|
||||
}
|
||||
await checkAuth();
|
||||
checkAuth();
|
||||
await Task.Delay(1);
|
||||
isLoading = false;
|
||||
await Task.Delay(1);
|
||||
|
||||
Reference in New Issue
Block a user