# 缓存清理功能实施计划
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** 在 topfans 移动端增加「存储空间」功能(WeChat 风格),按账号分组的可清理缓存管理,含黑名单保护 + 跨账号清理 + 内存层清理
**Architecture:**
- 统一封装层 `utils/cacheManager.js` 聚合 6 个 handler + 黑名单 + 配额统计
- 6 个独立 handler(preload / draft / progress / guide / sandboxTmp / others),分组型 handler 支持按 uid 分组清理
- UI 双页面:`cache-cleanup.vue`(列表 + WeChat 风格顶部)+ `cache-cleanup-detail.vue`(简单/分组模板按 id 分发)
- 前置迁移 M0:将草稿 storage key 从 `*` 改为 `*_${currentUid}`,解决跨账号草稿泄露
**Tech Stack:** Vue 3 组合式 API, uni-app 3.x, uni-storage (SQLite), plus.io (Android 10+ PRIVATE_DOC sandbox), preloadApi/core
**重要前置约束(CLAUDE.md 强制):**
- **AI 不自动 commit**:每个 commit 步骤前必须确认用户明确指示「帮我 commit」
- 不修改 `unpackage/dist/` 编译产物
- 新组件用 `
```
- [ ] **Step 3: 编译验证 + 实机查看**
Run: HBuilderX → 运行 → 真机/模拟器 → 进入 cache-cleanup 页面
预期:顶部大字显示、进度条显示、6 个分类行 + "其他" section 正常渲染
- [ ] **Step 4:(如用户授权)commit**
```bash
git add frontend/pages/profile/cache-cleanup.vue frontend/pages.json
git commit -m "feat(ui): add cache-cleanup list page with WeChat-style top"
```
---
## Task 22: 创建 pages/profile/cache-cleanup-detail.vue 简单页模板
**Files:**
- Create: `frontend/pages/profile/cache-cleanup-detail.vue`
- [ ] **Step 1: 在 pages.json 注册**
```json
{
"path": "pages/profile/cache-cleanup-detail",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": true
}
}
```
- [ ] **Step 2: 实现详情页(含简单/分组双模板)**
```vue
加载中…
{{ category?.description }}
{{ formatSize(simpleSize) }}
共 {{ simpleCount }} 项缓存
{{ category?.description }}
{{ formatSize(g.sizeBytes) }} · {{ g.keyCount }} 项
✓ 当前分类无缓存
```
- [ ] **Step 3: 编译 + 实机验证两个模板**
预期:
- 进入 preload / progress / sandbox-tmp / others → 简单页(单按钮)
- 进入 draft / guide → 分组页(多卡片 + 各自的清理按钮)
- [ ] **Step 4:(如用户授权)commit**
```bash
git add frontend/pages/profile/cache-cleanup-detail.vue frontend/pages.json
git commit -m "feat(ui): add cache-cleanup-detail page (simple + grouped templates)"
```
---
## Task 23: pages/profile/profile.vue 加「存储空间」菜单项
**Files:**
- Modify: `frontend/pages/profile/profile.vue`
- [ ] **Step 1: 找到 settings/menu list 区域**
查找 profile.vue 里的菜单项数组(如 `menuItems` 或类似的循环),加一项:
```js
{ id: 'storage', icon: '💾', label: '存储空间', url: '/pages/profile/cache-cleanup' }
```
- [ ] **Step 2: 实机验证**
进 profile 页面,能看到「存储空间」菜单项,点击进入 cache-cleanup 列表页正常显示。
- [ ] **Step 3:(如用户授权)commit**
```bash
git add frontend/pages/profile/profile.vue
git commit -m "feat(profile): add '存储空间' menu item"
```
---
## Task 24: M3 联调(端到端)
**Files:**
- 无(仅验证)
- [ ] **Step 1: 端到端流程验证(已登录态)**
1. 进 profile → 点「存储空间」→ cache-cleanup 列表页正常
2. 大字 + 百分比 + 进度条 + 3 chip + 6 分类 + "其他" section 全部显示
3. 点「预加载数据缓存」→ cache-cleanup-detail 简单页 → 点清理 → ConfirmModal → 确认 → loading → toast → 返回列表页自动刷新
4. 大字 / 进度条数字更新
- [ ] **Step 2: 分组清理验证**
1. 账号 A 登录,castlove 创作流写一些草稿(draftStorage 写入)
2. 退出账号 A,登录账号 B(uid 不同)
3. 进 cache-cleanup → 点「创作中的草稿」→ 分组页应显示 "我的草稿(uid=B)" + "其他用户的草稿(uid=A)"
4. 点 "其他用户的草稿" 卡片清理 → 强警告弹窗 → 确认 → toast
5. 返回列表页,"创作中的草稿" 大小应减少
- [ ] **Step 3: 未登录态分组页验证**
1. 退出登录
2. 进 cache-cleanup → 点「创作中的草稿」→ 分组页所有数据归"其他用户",按钮置灰
- [ ] **Step 4: 内存清理验证**
1. 列表页进 preload 详情页 → 清理 → 立刻返回列表页 → 数字更新(说明 memoryMap 已清)
2. console 检查:用导出的 `getStats()`(不是 memoryMap 字段,reviewer P0 修正):
```js
import('@/utils/preloadApi/core').then(c => console.log(c.getStats()))
// 期望: { hits: X, misses: Y, memorySize: 0, inFlightSize: 0, ... }
```
清理后 `memorySize` 和 `inFlightSize` 都应为 0
- [ ] **Step 5:(如用户授权)commit**
```bash
git add frontend/pages/profile/profile.vue frontend/pages/profile/cache-cleanup.vue frontend/pages/profile/cache-cleanup-detail.vue frontend/pages.json
git commit -m "feat(profile): add cache cleanup UI (list + detail pages)"
# E2E 验证在 PR description 中描述
```
---
# Phase 5: M4 — 13 个手工场景回归
## Task 25: 完整场景回归清单
**Files:**
- 无(仅验证)
- [ ] **Step 1: 13 个手工场景逐项验证**
完整场景列表(与 spec §7.3 对应):
| # | 场景 | 期望 | 验证 |
|---|------|------|------|
| 1 | 登录态清理简单页 | token/user/star_id/cid 不变 | ☐ |
| 2 | 登录态清理分组页-我的草稿 | 仅删 currentUid 草稿;普通警告 | ☐ |
| 3 | 登录态清理分组页-其他用户 | 仅删 otherUid 草稿;强警告;对方下次登录看不到 | ☐ |
| 4 | 未登录态清理简单页 | 全部业务缓存正常清理 | ☐ |
| 5 | 未登录态清理分组页 | 草稿/引导按钮置灰,不可清理 | ☐ |
| 6 | 清理中退出页面 | 不重复清理,不报错 | ☐ |
| 7 | 空缓存状态 | 列表页显示"✓ 当前无缓存可清理",无跳转入口 | ☐ |
| 8 | 草稿详情页(仅自己) | 仅显示"我的草稿"分组,清理按钮触发普通警告 | ☐ |
| 9 | 草稿详情页(多账号切换后) | 显示"我的草稿" + 多个"其他用户的草稿"分组;强警告+正常清理流程 | ☐ |
| 10 | 草稿详情页(未登录) | 所有数据归"其他用户",按钮置灰 | ☐ |
| 11 | 跨账号草稿隔离(A 写 → B 登录) | B 看不到 A 的草稿(依赖 §11 M0 改造) | ☐ |
| 12 | 跨账号 preload 清理 | A 的 preload 被 B 清理时一并清掉 | ☐ |
| 13 | 清理后立刻进列表页 | 不会从 memoryMap 命中老数据 | ☐ |
- [ ] **Step 2: CLAUDE.md 自检清单过一遍**
- [ ] 新组件用 `