feat: cache chat cards in Valkey
Valkey 9.1 in compose caches the immutable chat card (title, members,
created_at) used by GET /chats/{id} and by the membership check of the
message endpoints. Cache-aside with a write after commit, keys per
database, TTL plus allkeys-lru, persistence off. redis-py runs without
retries; on failure the cache is skipped for a few seconds and requests
go to PostgreSQL. Readiness does not depend on Valkey.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
"""Зависимости ручек: сессия БД, сервисы, вход и текущая сессия, страница."""
|
||||
"""Зависимости ручек: сессия БД, сервисы, вход и текущая сессия, страница.
|
||||
|
||||
Сервисы получают сессию БД, а чаты и сообщения — ещё и кэш процесса
|
||||
(`src/infra/cache/instance.py`).
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import base64
|
||||
@@ -21,6 +25,7 @@ from src.core.services import (
|
||||
SessionService,
|
||||
UserService,
|
||||
)
|
||||
from src.infra.cache.instance import cache
|
||||
from src.infra.db import is_db_unavailable, ping
|
||||
from src.infra.db.session import engine, session_factory
|
||||
from src.infra.logger import AbstractLogger, current_user_id, get_logger
|
||||
@@ -85,11 +90,11 @@ async def get_user_service(db_session: DbSessionDep) -> UserService:
|
||||
|
||||
|
||||
async def get_chat_service(db_session: DbSessionDep) -> ChatService:
|
||||
return ChatService(db_session=db_session)
|
||||
return ChatService(db_session=db_session, cache=cache)
|
||||
|
||||
|
||||
async def get_message_service(db_session: DbSessionDep) -> MessageService:
|
||||
return MessageService(db_session=db_session)
|
||||
return MessageService(db_session=db_session, cache=cache)
|
||||
|
||||
|
||||
async def get_session_service(db_session: DbSessionDep) -> SessionService:
|
||||
|
||||
Reference in New Issue
Block a user