From aefdecd0aa3226b7d00d1dc764241b82658b3be8 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 06 三月 2026 10:41:02 +0800
Subject: [PATCH] 添加机器人客户端;更新 WCS 缓存及任务
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Caches/MemoryCacheService.cs | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Caches/MemoryCacheService.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Caches/MemoryCacheService.cs
index a1c7c18..1daeb3a 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Caches/MemoryCacheService.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Caches/MemoryCacheService.cs
@@ -392,6 +392,28 @@
return true;
}
+ public bool TrySafeUpdate<T>(
+ string key,
+ T newValue,
+ object? expectedVersion,
+ Func<T, object?> versionExtractor,
+ int expireSeconds = -1) where T : class
+ {
+ var existing = Get<T>(key);
+ if (existing == null) return false;
+
+ // 妫�鏌ョ増鏈槸鍚﹀尮閰�
+ var currentVersion = versionExtractor(existing);
+ if (!Equals(currentVersion, expectedVersion))
+ {
+ return false; // 鐗堟湰涓嶅尮閰嶏紝鎷掔粷鏇存柊
+ }
+
+ Remove(key);
+ AddObject(key, newValue, expireSeconds);
+ return true;
+ }
+
public string GetOrAdd(string key, string value, int expireSeconds = -1)
{
var existing = _cache.Get(key)?.ToString();
--
Gitblit v1.9.3