增加缓存
This commit is contained in:
@@ -12,7 +12,9 @@ using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Erp;
|
||||
using WMS.Web.Core.Dto.JuShuiTan;
|
||||
using WMS.Web.Core.Help;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
using WMS.Web.Domain.IService.Public;
|
||||
using WMS.Web.Domain.Options;
|
||||
@@ -26,7 +28,6 @@ namespace WMS.Web.Domain.Services.Public
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
private int hours = 10;//过期时间 默认10小时
|
||||
private readonly JuShuiTanOptions _option;
|
||||
|
||||
public JuShuiTanService(IHttpClientService httpClientService, ILogger<JuShuiTanService> logger,
|
||||
IMemoryCache memoryCache, IOptions<JuShuiTanOptions> option)
|
||||
{
|
||||
@@ -45,6 +46,10 @@ namespace WMS.Web.Domain.Services.Public
|
||||
|
||||
public async Task<Result<List<JuShuiTanStockResponse>>> GetStock()
|
||||
{
|
||||
var stock_list = _memoryCache.Get<List<JuShuiTanStockResponse>>("jushuitan_stock");
|
||||
if (stock_list != null && stock_list.Count > 0)
|
||||
return Result<List<JuShuiTanStockResponse>>.ReSuccess(stock_list);
|
||||
|
||||
List<JuShuiTanStockResponse> list = new List<JuShuiTanStockResponse>();
|
||||
|
||||
JuShuiTanStockRequst request = new JuShuiTanStockRequst();
|
||||
@@ -70,6 +75,9 @@ namespace WMS.Web.Domain.Services.Public
|
||||
datas = JsonConvert.DeserializeObject<List<JuShuiTanStockResponse>>(json);
|
||||
list.AddRange(datas);
|
||||
}
|
||||
|
||||
//设置缓存
|
||||
_memoryCache.Set("jushuitan_stock", list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(DateTimeUtil.GetTotalMinutesTimeSpan())));
|
||||
return Result<List<JuShuiTanStockResponse>>.ReSuccess(list);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user