- 新增 system_cache 模块与 POST /settings/cache/clear,管理员可一键清理 OCR 结果/运行时配置/模型失败冷却/知识库索引/地点语义等进程内缓存 - 各服务暴露 clear_*_cache 方法(ocr/runtime_settings/runtime_chat/knowledge/application_location_semantic),SettingsCacheClearRead 汇总清理项 - OCR 转图片失败时尝试用 PDF 文本层兜底构建识别文档(有效字符≥8),并写结果缓存;OcrService 暴露 clear_result_cache - receipt_folder 车票过滤补充身份证号关键词,附件文档/操作/展示模块同步适配 - 新增 system_cache_endpoints 测试,更新 openapi_schema/ocr/receipt_folder/attachment_association_jobs 测试
42 lines
1.8 KiB
Python
42 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from app.core.config import clear_runtime_settings_cache
|
|
from app.schemas.settings import SettingsCacheClearItemRead, SettingsCacheClearRead
|
|
from app.services.application_location_semantics import clear_application_location_semantic_caches
|
|
from app.services.knowledge_rag_local import clear_local_knowledge_index_cache
|
|
from app.services.ocr import OcrService
|
|
from app.services.runtime_chat import clear_runtime_chat_failure_cache
|
|
|
|
|
|
class SystemCacheService:
|
|
def clear_all(self) -> SettingsCacheClearRead:
|
|
items = [
|
|
SettingsCacheClearItemRead(
|
|
cacheKey="ocr_result_cache",
|
|
label="OCR 识别结果缓存",
|
|
clearedCount=OcrService.clear_result_cache(),
|
|
),
|
|
SettingsCacheClearItemRead(
|
|
cacheKey="runtime_settings_cache",
|
|
label="运行时配置缓存",
|
|
clearedCount=clear_runtime_settings_cache(),
|
|
),
|
|
SettingsCacheClearItemRead(
|
|
cacheKey="runtime_chat_failure_cache",
|
|
label="模型调用失败冷却缓存",
|
|
clearedCount=clear_runtime_chat_failure_cache(),
|
|
),
|
|
SettingsCacheClearItemRead(
|
|
cacheKey="knowledge_local_index_cache",
|
|
label="知识库本地索引缓存",
|
|
clearedCount=clear_local_knowledge_index_cache(),
|
|
),
|
|
SettingsCacheClearItemRead(
|
|
cacheKey="application_location_semantic_cache",
|
|
label="地点语义分析缓存",
|
|
clearedCount=clear_application_location_semantic_caches(),
|
|
),
|
|
]
|
|
total_cleared = sum(item.clearedCount for item in items)
|
|
return SettingsCacheClearRead(totalCleared=total_cleared, items=items)
|