test update api
This commit is contained in:
@@ -28,7 +28,7 @@ namespace LiMan.APi.Data
|
||||
private static ILogger<ApiDataService> _logger;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private readonly IEmailSender _emailSender;
|
||||
private readonly IDistributedCache distributedCache;
|
||||
//private readonly IDistributedCache distributedCache;
|
||||
private readonly IRedisCacheClient _redisCacheClient;
|
||||
|
||||
/// <summary>
|
||||
@@ -74,7 +74,21 @@ namespace LiMan.APi.Data
|
||||
protected async Task<bool> setRSV(string rKey, string rVal, int ttlSec)
|
||||
{
|
||||
bool fatto = false;
|
||||
await _redisCacheClient.GetDbFromConfiguration().AddAsync<string>(rKey, rVal, DateTimeOffset.Now.AddSeconds(ttlSec));
|
||||
await _redisCacheClient.GetDbFromConfiguration().AddAsync(rKey, rVal, DateTimeOffset.Now.AddSeconds(ttlSec));
|
||||
fatto = true;
|
||||
return fatto;
|
||||
}
|
||||
/// <summary>
|
||||
/// Salvataggio chiave in redis
|
||||
/// </summary>
|
||||
/// <param name="rKey"></param>
|
||||
/// <param name="rValInt"></param>
|
||||
/// <param name="ttlSec"></param>
|
||||
/// <returns></returns>
|
||||
protected async Task<bool> setRSV(string rKey, int rValInt, int ttlSec)
|
||||
{
|
||||
bool fatto = false;
|
||||
await _redisCacheClient.GetDbFromConfiguration().AddAsync<int>(rKey, rValInt, DateTimeOffset.Now.AddSeconds(ttlSec));
|
||||
fatto = true;
|
||||
return fatto;
|
||||
}
|
||||
@@ -90,13 +104,14 @@ namespace LiMan.APi.Data
|
||||
/// <param name="distributedCache"></param>
|
||||
/// <param name="emailSender"></param>
|
||||
/// <param name="redisCacheClient"></param>
|
||||
public ApiDataService(IConfiguration configuration, ILogger<ApiDataService> logger, IDistributedCache distributedCache, IEmailSender emailSender, IRedisCacheClient redisCacheClient)
|
||||
public ApiDataService(IConfiguration configuration, ILogger<ApiDataService> logger, IEmailSender emailSender, IRedisCacheClient redisCacheClient)
|
||||
//public ApiDataService(IConfiguration configuration, ILogger<ApiDataService> logger, IDistributedCache distributedCache, IEmailSender emailSender, IRedisCacheClient redisCacheClient)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_emailSender = emailSender;
|
||||
this.distributedCache = distributedCache;
|
||||
_redisCacheClient = redisCacheClient;
|
||||
//this.distributedCache = distributedCache;
|
||||
|
||||
// conf DB
|
||||
string connStrDB = _configuration.GetConnectionString("LiMan.DB");
|
||||
@@ -332,6 +347,7 @@ namespace LiMan.APi.Data
|
||||
{
|
||||
LicenzaModel dbResult = new LicenzaModel();
|
||||
string cacheKey = $"DATA:Licenze:ListByKey:{chiave}";
|
||||
#if false
|
||||
string rawData;
|
||||
var redisDataList = await distributedCache.GetAsync(cacheKey);
|
||||
if (redisDataList != null)
|
||||
@@ -350,7 +366,26 @@ namespace LiMan.APi.Data
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per LicenzaByMasterKey: {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
#endif
|
||||
|
||||
string rawData = await getRSV(cacheKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
dbResult = JsonConvert.DeserializeObject<LicenzaModel>(rawData);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = dbController.LicenzaByKey(chiave);
|
||||
rawData = JsonConvert.SerializeObject(dbResult);
|
||||
await setRSV(cacheKey, rawData, hourTTL);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Trace($"Effettuata lettura da DB per LicenzaByMasterKey: {ts.TotalMilliseconds} ms");
|
||||
}
|
||||
|
||||
return await Task.FromResult(dbResult);
|
||||
}
|
||||
|
||||
@@ -482,7 +517,7 @@ namespace LiMan.APi.Data
|
||||
int.TryParse(rawVal, out currCount);
|
||||
}
|
||||
currCount++;
|
||||
answ = await setRSV(rKey, $"{currCount}", 2 * hourTTL);
|
||||
answ = await setRSV(rKey, currCount, 2 * hourTTL);
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -493,7 +528,7 @@ namespace LiMan.APi.Data
|
||||
{
|
||||
bool answ = false;
|
||||
int currCount = 0;
|
||||
answ = await setRSV(rKey, $"{currCount}", 2 * hourTTL);
|
||||
answ = await setRSV(rKey, currCount, 2 * hourTTL);
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -242,7 +242,16 @@
|
||||
<param name="ttlSec"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LiMan.APi.Data.ApiDataService.#ctor(Microsoft.Extensions.Configuration.IConfiguration,Microsoft.Extensions.Logging.ILogger{LiMan.APi.Data.ApiDataService},Microsoft.Extensions.Caching.Distributed.IDistributedCache,Microsoft.AspNetCore.Identity.UI.Services.IEmailSender,StackExchange.Redis.Extensions.Core.Abstractions.IRedisCacheClient)">
|
||||
<member name="M:LiMan.APi.Data.ApiDataService.setRSV(System.String,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
Salvataggio chiave in redis
|
||||
</summary>
|
||||
<param name="rKey"></param>
|
||||
<param name="rValInt"></param>
|
||||
<param name="ttlSec"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:LiMan.APi.Data.ApiDataService.#ctor(Microsoft.Extensions.Configuration.IConfiguration,Microsoft.Extensions.Logging.ILogger{LiMan.APi.Data.ApiDataService},Microsoft.AspNetCore.Identity.UI.Services.IEmailSender,StackExchange.Redis.Extensions.Core.Abstractions.IRedisCacheClient)">
|
||||
<summary>
|
||||
Init classe
|
||||
</summary>
|
||||
|
||||
Reference in New Issue
Block a user