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']