# PR #32484 完整报告

- 仓库：`sgl-project/sglang`
- 标题：[UnifiedTree]: move /mem_cache/unifed_cache_component dir to /mem_cache/unified_cache
- 合并时间：2026-07-28 16:28
- 原文链接：http://prhub.com.cn/sgl-project/sglang/pull/32484

---

# 执行摘要

- 一句话：重命名 unified_cache_components 目录为 unified_cache/components
- 推荐动作：该 PR 是纯粹的目录结构整理，值得关注的是 unified_cache 模块的内聚设计决策。建议代码审查者确认所有 import 更新无误。

# 功能与动机

该 PR 主要目的是整理 mem_cache 模块的目录结构，将之前分散在 unified_cache_components 中的组件统一纳入 unified_cache 子目录，减少顶层目录数量，提高代码可维护性。

# 实现拆解

1. 创建新目录 python/sglang/srt/mem_cache/unified_cache/components，并将四个文件从旧路径 unified_cache_components 移动过来：full_component.py、mamba_component.py、swa_component.py、tree_component.py（包含核心类型定义）。
2. 更新每个移动后文件的内部 import，使其指向新的相对路径。
3. 更新所有引用旧路径的源文件（共 23 个）中的 import 语句，包括 unified_tree_core.py、unified_radix_cache.py、unified_tree_core_interface.py、tree_core_registry.py 以及其他外围模块。
4. 配套测试文件也进行了相应 import 更新。
5. 移除旧的 unified_cache_components 目录。

关键文件：
- `python/sglang/srt/mem_cache/unified_cache/unified_tree_core.py`（模块 缓存层；类别 source；类型 dependency-wiring）: 核心树缓存实现文件，更新了导入 unified_cache_components 的路径，改为从 unified_cache.components 导入。
- `python/sglang/srt/mem_cache/unified_cache/components/__init__.py`（模块 缓存层；类别 source；类型 rename-or-move）: 新目录的 __init__.py，将四个组件的 import 路径从旧位置更新到新位置。
- `python/sglang/srt/mem_cache/unified_radix_cache.py`（模块 缓存层；类别 source；类型 dependency-wiring）: 统一 radix cache 控制器，更新了组件导入路径。
- `python/sglang/srt/mem_cache/unified_cache/unified_tree_core_interface.py`（模块 缓存层；类别 source；类型 dependency-wiring）: 树核心接口，更新了 types 导入路径。
- `python/sglang/srt/mem_cache/unified_cache/components/full_component.py`（模块 缓存层；类别 source；类型 rename-or-move）: FullComponent 实现文件，移动后更新内部导入。
- `python/sglang/srt/mem_cache/unified_cache/components/mamba_component.py`（模块 缓存层；类别 source；类型 rename-or-move）: MambaComponent 实现文件，移动后更新内部导入。

关键符号：未识别

## 关键源码片段

### `python/sglang/srt/mem_cache/unified_cache/unified_tree_core.py`

核心树缓存实现文件，更新了导入 unified_cache_components 的路径，改为从 unified_cache.components 导入。

```python
# 变更前：
# from sglang.srt.mem_cache.unified_cache_components import (
# ...
# )

# 变更后：
from sglang.srt.mem_cache.unified_cache.components import (
    _NUM_COMPONENT_TYPES,
    BASE_COMPONENT_TYPE,
    CacheTransferPhase,
    ComponentData,
    ComponentType,
    EvictLayer,
    LRURefreshPhase,
    TreeComponent,
    get_and_increase_time_counter,
)

```

### `python/sglang/srt/mem_cache/unified_cache/components/__init__.py`

新目录的 __init__.py，将四个组件的 import 路径从旧位置更新到新位置。

```python
# 新位置：python/sglang/srt/mem_cache/unified_cache/components/__init__.py
# 所有导入均指向新路径下的模块

from sglang.srt.mem_cache.unified_cache.components.full_component import FullComponent
from sglang.srt.mem_cache.unified_cache.components.mamba_component import MambaComponent
from sglang.srt.mem_cache.unified_cache.components.swa_component import SWAComponent
from sglang.srt.mem_cache.unified_cache.components.tree_component import (
    _NUM_COMPONENT_TYPES,
    BASE_COMPONENT_TYPE,
    CacheTransferPhase,
    ComponentData,
    ComponentType,
    EvictLayer,
    LRURefreshPhase,
    PrepareLoadBackResult,
    PreparePrefetchResult,
    TreeComponent,
    get_and_increase_time_counter,
    next_component_uuid,
)

__all__ = [
    "BASE_COMPONENT_TYPE",
    "ComponentData",
    "ComponentType",
    "EvictLayer",
    "FullComponent",
    "CacheTransferPhase",
    "LRURefreshPhase",
    "MambaComponent",
    "PrepareLoadBackResult",
    "PreparePrefetchResult",
    "SWAComponent",
    "TreeComponent",
    "_NUM_COMPONENT_TYPES",
    "next_component_uuid",
    "get_and_increase_time_counter",
]

```

# 评论区精华

该 PR 无 review 评论，CI 全部通过。

- 暂无高价值评论线程

# 风险与影响

- 风险：风险极低。所有变更为纯 import 路径调整，无逻辑改动。CI 已验证 4 组 unittest 通过。但若存在未跟踪的 import（如动态加载），可能遗漏，本 PR 未涉及动态加载。
- 影响：对内部开发者的影响：需要更新开发分支中的 import 路径；对用户无影响，功能行为完全不变。
- 风险标记：纯 import 变更 , CI 已通过

# 关联脉络

- 暂无明显关联 PR