wanshenmean
8 天以前 fd18eaba5e1c086a588509371f91310e7aafff9c
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Caches/ICacheService.cs
@@ -247,6 +247,24 @@
        bool TryUpdateIfChanged<T>(string key, T newValue, int expireSeconds = -1) where T : class;
        /// <summary>
        /// 安全更新:仅当内存缓存中的值与expectedVersion匹配时才更新
        /// 防止并发写入时旧值覆盖新值(适用于多线程/多进程场景)
        /// </summary>
        /// <typeparam name="T">值类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="newValue">新值</param>
        /// <param name="expectedVersion">期望的版本(通常是旧对象的某个属性值,如时间戳)</param>
        /// <param name="versionExtractor">从对象提取版本号的函数</param>
        /// <param name="expireSeconds">过期时间(秒)</param>
        /// <returns>是否更新成功</returns>
        bool TrySafeUpdate<T>(
            string key,
            T newValue,
            object? expectedVersion,
            Func<T, object?> versionExtractor,
            int expireSeconds = -1) where T : class;
        /// <summary>
        /// 获取或添加:Key存在则返回现有值,不存在则添加并返回新值
        /// </summary>
        string GetOrAdd(string key, string value, int expireSeconds = -1);