- Introduced `TemplateService` for managing SQL templates, allowing for parameterized queries based on user input. - Added functionality to automatically reload templates upon asset creation in `analyst.py`. - Enhanced `CacheService` to support table generation bumping, ensuring cache invalidation on data changes. - Updated `RiskRepository` and `GatewayRepository` to trigger cache invalidation for relevant operations. - Expanded `analyst_schemas.py` to include new fields for template tracking in response metadata. - Created seed SQL script for populating initial templates and added unit tests for template rendering logic. This update significantly improves the efficiency of query handling by leveraging SQL templates, reducing reliance on LLM for common queries.
35 lines
788 B
Python
35 lines
788 B
Python
"""问数结果缓存主动失效(D-06 写侧钩子入口)。
|
|
|
|
事实表变更时 bump 表世代,fail-open(缓存失效失败不阻断业务写)。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from app.service.cache_service import CacheService
|
|
|
|
_svc: CacheService | None = None
|
|
|
|
|
|
def _service() -> CacheService:
|
|
global _svc
|
|
if _svc is None:
|
|
_svc = CacheService.auto()
|
|
return _svc
|
|
|
|
|
|
def bump_analyst_cache(*tables: str) -> None:
|
|
if not tables:
|
|
return
|
|
_service().invalidate_tables(tables)
|
|
|
|
|
|
def bump_analyst_cache_for_trade() -> None:
|
|
bump_analyst_cache("core_trade")
|
|
|
|
|
|
def bump_analyst_cache_for_risk_alert() -> None:
|
|
bump_analyst_cache("risk_alert")
|
|
|
|
|
|
def bump_analyst_cache_for_l3() -> None:
|
|
bump_analyst_cache("customer_profile_l3")
|