Refactor cache L2 storage to use SQLAlchemy DB

Replaces the L2 cache layer's SQLite implementation with an async SQLAlchemy-based database model (CacheEntries). Updates cache_manager.py to use db_query and db_save for cache operations, adds semantic cache handling with ChromaDB, and introduces async cache clearing and expiration cleaning methods. Adds the CacheEntries model and integrates it into the database API.
This commit is contained in:
雅诺狐
2025-08-18 18:30:17 +08:00
parent 7856c6a8e9
commit bcbcabb0d8
3 changed files with 233 additions and 90 deletions

View File

@@ -15,7 +15,8 @@ from src.common.logger import get_logger
from src.common.database.sqlalchemy_models import (
Base, get_db_session, Messages, ActionRecords, PersonInfo, ChatStreams,
LLMUsage, Emoji, Images, ImageDescriptions, OnlineTime, Memory,
Expression, ThinkingLog, GraphNodes, GraphEdges, Schedule, MaiZoneScheduleStatus
Expression, ThinkingLog, GraphNodes, GraphEdges, Schedule, MaiZoneScheduleStatus,
CacheEntries
)
logger = get_logger("sqlalchemy_database_api")
@@ -38,6 +39,7 @@ MODEL_MAPPING = {
'GraphEdges': GraphEdges,
'Schedule': Schedule,
'MaiZoneScheduleStatus': MaiZoneScheduleStatus,
'CacheEntries': CacheEntries,
}