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:
@@ -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,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user