Delete js/services/缓存说明.md

This commit is contained in:
诶~阿伟哥
2025-06-21 23:27:51 +08:00
committed by GitHub
parent 4cbf51e54a
commit f182f8a9db
-315
View File
@@ -1,315 +0,0 @@
控制台中查看缓存的方法
历史缓存
JSON.parse(localStorage.getItem('history_cache_all'))
翻译缓存
JSON.parse(localStorage.getItem('translate_cache_pairs'))
标签缓存
Object.keys(localStorage)
.filter(key => key.startsWith('tag_cache_'))
.map(key => ({ key, value: JSON.parse(localStorage.getItem(key)) }))
# 缓存说明
## 历史记录缓存
### 缓存结构
历史记录缓存使用 localStorage 存储,键名格式为 `history_cache_${node_id}_${input_id}`。
每个缓存项包含以下字段:
- workflow_id: 工作流ID
- node_id: 节点ID
- input_id: 输入框ID
- content: 内容
- operation_type: 操作类型(input/translate/original)
- request_id: 请求ID(用于关联原文和译文)
- timestamp: 时间戳
### 查看缓存内容
#### 查看所有实例
```javascript
// 如果 PromptAssistant 已挂载到 window.app
Array.from(window.app.promptAssistant.instances.entries())
```
#### 查看所有实例的键
```javascript
// 获取所有实例的键
Array.from(window.app.promptAssistant.instances.keys())
```
#### 查看所有实例的值
```javascript
// 获取所有实例的值
Array.from(window.app.promptAssistant.instances.values())
```
#### 查看所有实例的键值对
```javascript
// 获取所有实例的键值对
Array.from(promptAssistant.instances.entries())
```
#### 查看特定实例
```javascript
// 获取特定实例
window.app.promptAssistant.instances.get('3_text')
```
### 说明
- 所有实例都保存在 `window.app.promptAssistant.instances` 这个 Map 里。
- 用 `Array.from(window.app.promptAssistant.instances.entries())` 可以完整查看所有实例。
## 标签缓存
### 缓存结构
标签缓存使用 localStorage 存储,键名格式为 `tag_cache_${node_id}_${input_id}`。
每个缓存项包含以下字段:
- zh: 中文标签
- en: 英文标签
- count: 使用次数
- lastUsed: 最后使用时间
### 查看缓存内容
```javascript
// 获取所有标签缓存
Object.keys(localStorage).filter(key => key.startsWith('tag_cache_'))
```
### 说明
- 标签缓存按节点和输入框分别存储
- 使用次数和最后使用时间用于排序和推荐
我来帮你分析一下历史缓存和标签缓存的数据结构。
### 1. 历史缓存 (HistoryCacheService)
历史缓存的数据以数组形式存储在 localStorage 中,键名为 `history_cache_all`。每条历史记录是一个对象,结构如下:
```javascript
{
node_id: string, // 节点ID
input_id: string, // 输入框ID
content: string, // 内容
operation_type: string, // 操作类型,默认为 "input"
timestamp: number // 时间戳
}
```
同时,还维护了一个内存中的撤销/重做状态 Map(undoStates),结构如下:
```javascript
// key: `${nodeId}_${inputId}`
// value:
{
currentIndex: number, // 当前在历史记录中的位置
currentContent: string, // 当前内容
lastHistoryTimestamp: number // 最后一次历史记录的时间戳
}
```
主要限制:
- 每个节点最多保存 20 条历史记录 (MAX_HISTORY_PER_NODE)
- 全局最多保存 100 条历史记录 (MAX_HISTORY_GLOBAL)
- 单条历史记录最大长度 5000 字符 (MAX_CONTENT_LENGTH)
### 2. 标签缓存 (TagCacheService)
标签缓存以 Map 形式存储在 localStorage 中,键名格式为 `tag_cache_${nodeId}_${inputId}`。数据结构如下:
```javascript
{
// key: rawTag (原始标签)
// value: 标签格式对象
"rawTag1": {
format1: string, // 格式1:" tagContent"
format2: string, // 格式2:" tagContent,"
format3: string, // 格式3:", tagContent,"
insertedFormat: string // 实际插入的格式
},
"rawTag2": {
// ... 同上
}
}
```
举个例子:
```javascript
{
"beautiful girl": {
format1: " beautiful girl",
format2: " beautiful girl,",
format3: ", beautiful girl,",
insertedFormat: ", beautiful girl,"
}
}
```
特点:
1. 历史缓存是全局统一存储的,通过 node_id 和 input_id 来区分不同节点和输入框的历史
2. 标签缓存是按节点和输入框分开存储的,每个输入框有自己独立的标签缓存
3. 两种缓存都使用 localStorage 作为持久化存储
4. 历史缓存有数量限制,而标签缓存没有明确的数量限制
这样的设计允许:
1. 在不同节点间共享和查看历史记录
2. 为每个输入框维护独立的标签集合
3. 支持撤销/重做操作
4. 支持标签的多种格式化展示
---
## 1. 查看所有标签缓存 key
标签缓存的 key 一般是 `tag_cache_<nodeId>_<inputId>` 这种格式。
你可以先列出所有 localStorage 的 key,找到以 `tag_cache_` 开头的:
```js
// 列出所有标签缓存 key
Object.keys(localStorage).filter(key => key.startsWith('tag_cache_'))
```
---
## 2. 查看某个节点/输入框的标签缓存内容
假设你要看节点3、输入框text的标签缓存:
```js
JSON.parse(localStorage.getItem('tag_cache_3_text'))
```
- 这会输出一个对象,key 是原始标签,value 是标签的格式化信息。
---
## 3. 查看所有标签缓存内容
你可以批量查看所有标签缓存:
```js
Object.keys(localStorage)
.filter(key => key.startsWith('tag_cache_'))
.map(key => ({ key, value: JSON.parse(localStorage.getItem(key)) }))
```
---
## 总结
- 标签缓存 key 格式:`tag_cache_<nodeId>_<inputId>`
- 用 `localStorage.getItem('tag_cache_3_text')` 查看具体内容
- 用 `Object.keys(localStorage).filter(key => key.startsWith('tag_cache_'))` 列出所有标签缓存
如需进一步分析标签缓存内容,欢迎继续提问!
你可以在浏览器控制台(Console)中这样查看本地历史缓存文件(即 localStorage 里的历史记录):
---
### 1. 查看所有历史记录
```js
JSON.parse(localStorage.getItem('history_cache_all'))
```
- 这会输出一个数组,包含所有历史记录对象。
---
### 2. 查看某个节点的历史记录
假设你要看节点3的历史:
```js
JSON.parse(localStorage.getItem('history_cache_all')).filter(item => String(item.node_id) === '3')
```
---
### 3. 查看历史缓存 key 是否存在
```js
localStorage.getItem('history_cache_all') !== null
```
---
### 4. 查看历史缓存条数
```js
(JSON.parse(localStorage.getItem('history_cache_all')) || []).length
```
---
**总结:**
- 历史缓存文件的 key 是 `history_cache_all`。
- 用 `JSON.parse(localStorage.getItem('history_cache_all'))` 查看全部内容。
如需进一步分析或筛选历史内容,可以继续提问!
你可以在浏览器控制台中这样查看当前所有"小助手实例":
---
### 1. 查看所有实例的 key 和内容
```js
// 如果 AssistantManager 已挂载到 window.app
Array.from(window.app.AssistantManager.instances.entries())
```
- 这会输出一个数组,每一项是 `[key, 实例对象]`,key 通常是 `nodeId_inputId`。
---
### 2. 只看所有实例的 key
```js
Array.from(window.app.AssistantManager.instances.keys())
```
---
### 3. 只看所有实例的详细内容
```js
Array.from(window.app.AssistantManager.instances.values())
```
---
### 4. 如果你用的不是 window.app,可以直接用全局变量
```js
// 直接全局变量(如果有)
Array.from(AssistantManager.instances.entries())
```
---
### 5. 查看单个实例
假设你要看 key 为 `3_text` 的实例:
```js
window.app.AssistantManager.instances.get('3_text')
```
---
**总结:**
- 所有实例都保存在 `window.app.AssistantManager.instances` 这个 Map 里。
- 用 `Array.from(window.app.AssistantManager.instances.entries())` 可以完整查看所有实例。