From 634dc6c855ca81322fcc3b65205949d87a6a21eb Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 24 Jan 2026 22:57:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(cache):=20=E8=A7=A3=E5=86=B3=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=B8=85=E7=90=86=E6=97=B6=E5=88=A0=E9=99=A4=E6=AD=A3?= =?UTF-8?q?=E5=9C=A8=E4=BD=BF=E7=94=A8=E7=9A=84=E6=96=87=E4=BB=B6=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加文件锁定检查机制避免删除正在使用的缓存文件 - 实现基于文件名提取cache_key的锁定状态检测 - 在删除前验证锁文件是否存在以确保安全清理 - 添加调试日志记录跳过的锁定文件信息 --- services/cache.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/cache.py b/services/cache.py index 73d63f7..89dc7ae 100644 --- a/services/cache.py +++ b/services/cache.py @@ -292,6 +292,14 @@ class MaterialCache: for file_info in cache_files: if total_size <= target_size: break + # 从文件名提取 cache_key,检查是否有锁(说明正在被使用) + filename = os.path.basename(file_info['path']) + cache_key = os.path.splitext(filename)[0] + lock_path = self._get_lock_path(cache_key) + if os.path.exists(lock_path): + # 该文件正在被其他任务使用,跳过删除 + logger.debug(f"Cache cleanup: skipping locked file {filename}") + continue try: os.remove(file_info['path']) total_size -= file_info['size']