From b7ee8c173ae75cfe32e58cc42020267fd155158a Mon Sep 17 00:00:00 2001
From: xxyy <cathay_xy@163.com>
Date: 星期五, 07 三月 2025 15:30:48 +0800
Subject: [PATCH] 增强缓存操作的线程安全性
---
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs | 15 ++++++++++++---
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskController.cs | 2 +-
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs | 40 ++++++++++++++++++++--------------------
3 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
index 9f34503..6d021a8 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -137,12 +137,18 @@
});
try
{
- _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode });
+ using(_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000))
+ {
+ _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode });
+ }
}
catch (Exception ex)
{
LogFactory.GetLog("鍒犻櫎缂撳瓨澶辫触").Error(true, $"{stock.PalletCode}_鍒犻櫎缂撳瓨澶辫触锛屽紓甯镐俊鎭細{ex.Message}");
- _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode });
+ using(_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000))
+ {
+ _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode });
+ }
}
return content.OK("浠诲姟瀹屾垚鎴愬姛", task.Remark);
@@ -380,7 +386,10 @@
_locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(locationInf, lastStatus, (int)StatusChangeTypeEnum.AutomaticStorage, task.TaskNum);
stock.StockInfoDetails = new List<DtStockInfoDetail>() { { stock.StockInfoDetails[0] } };
- _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, stock.PalletCode, stock);
+ using(_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000))
+ {
+ _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, stock.PalletCode, stock);
+ }
content.OK("鍏ュ簱浠诲姟瀹屾垚鎴愬姛");
}
diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
index 6714028..acb5069 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
@@ -894,26 +894,26 @@
WebResponseContent content = new WebResponseContent();
try
{
- string requestKey = JsonConvert.SerializeObject(taskDTO);
- // 妫�鏌ヨ姹傛鏁板拰鏃堕棿闄愬埗
- if (requestTrackerToCW.TryGetValue(requestKey, out var requestInfo))
- {
- if (requestInfo.Count > 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(2))
- {
- // 濡傛灉璇锋眰娆℃暟瓒呰繃闄愬埗涓旀湭瓒呰繃10鍒嗛挓锛屾姏鍑哄紓甯�
- throw new InvalidOperationException("璇锋眰娆℃暟宸茶揪鍒伴檺鍒讹紝璇风◢鍚庡啀璇曘��");
- }
- }
+ //string requestKey = JsonConvert.SerializeObject(taskDTO);
+ //// 妫�鏌ヨ姹傛鏁板拰鏃堕棿闄愬埗
+ //if (requestTrackerToCW.TryGetValue(requestKey, out var requestInfo))
+ //{
+ // if (requestInfo.Count > 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(2))
+ // {
+ // // 濡傛灉璇锋眰娆℃暟瓒呰繃闄愬埗涓旀湭瓒呰繃10鍒嗛挓锛屾姏鍑哄紓甯�
+ // throw new InvalidOperationException("璇锋眰娆℃暟宸茶揪鍒伴檺鍒讹紝璇风◢鍚庡啀璇曘��");
+ // }
+ //}
- // 鏇存柊璇锋眰璺熻釜淇℃伅
- if (requestTrackerToCW.ContainsKey(requestKey))
- {
- requestTrackerToCW[requestKey] = (requestInfo.Count + 1, DateTime.Now);
- }
- else
- {
- requestTrackerToCW[requestKey] = (1, DateTime.Now);
- }
+ //// 鏇存柊璇锋眰璺熻釜淇℃伅
+ //if (requestTrackerToCW.ContainsKey(requestKey))
+ //{
+ // requestTrackerToCW[requestKey] = (requestInfo.Count + 1, DateTime.Now);
+ //}
+ //else
+ //{
+ // requestTrackerToCW[requestKey] = (1, DateTime.Now);
+ //}
var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == taskDTO.Position && x.stationStatus == "1");
var locations = _locationRepository.QueryData(x => x.RoadwayNo == station.Roadway && x.LocationStatus == (int)LocationEnum.Free && x.LocationType == 1);
@@ -947,7 +947,7 @@
_locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum);
// 杩斿洖鎴愬姛鍝嶅簲
- requestTrackerToCW.Remove(requestKey);
+ //requestTrackerToCW.Remove(requestKey);
return content.OK(data: wmsTask);
}
diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskController.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskController.cs
index a13835a..cd1bff6 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskController.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskController.cs
@@ -162,7 +162,7 @@
/// <param name="input">璇锋眰鏁版嵁</param>
/// <returns></returns>
[HttpPost, AllowAnonymous, Route("GetFROutTrayToCW")]
- [TypeFilter(typeof(ThrottleFilter), Arguments = new object[] { 5 })] // 5绉掕妭娴�
+ [TypeFilter(typeof(ThrottleFilter), Arguments = new object[] { 15 })] // 5绉掕妭娴�
public async Task<WebResponseContent> GetFROutTrayToCW([FromBody] RequestTaskDto input)
{
return await Service.GetFROutTrayToCW(input);
--
Gitblit v1.9.3