feat(ai): 实现 CacheService 两级缓存 + 集成到 AiState

Redis TTL (L1) + DB SHA-256 hash (L2),Redis 不可用时自动降级
CacheKey 基于 tenant_id + analysis_type + input_hash + prompt_version
AiState 新增 cache 字段,main.rs 注入共享 Redis Client
This commit is contained in:
iven
2026-05-05 15:33:58 +08:00
parent 50b9e8d683
commit c268229311
5 changed files with 255 additions and 0 deletions

View File

@@ -535,6 +535,12 @@ async fn main() -> anyhow::Result<()> {
db.clone(),
config.ai.quota_check_enabled,
));
let cache_ttl = std::time::Duration::from_secs(config.ai.cache_ttl_seconds);
let cache = std::sync::Arc::new(erp_ai::service::cache::CacheService::new(
redis_client.clone(),
db.clone(),
cache_ttl,
));
erp_ai::AiState {
db: db.clone(),
@@ -546,6 +552,7 @@ async fn main() -> anyhow::Result<()> {
health_provider,
provider_registry: registry,
quota,
cache,
}
};