level 4: redis cache etc

This commit is contained in:
2026-10-26 17:50:20 +03:00
parent 9d3de3b2d9
commit 175a8d8bfd
14 changed files with 686 additions and 78 deletions
+7 -2
View File
@@ -10,6 +10,7 @@ from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from starlette.exceptions import HTTPException as StarletteHTTPException
from .cache import SessionCache, open_cache
from .config import load_settings
from .db import open_pool
from .errors import ApiError
@@ -58,12 +59,16 @@ _OPENAPI_PATH = Path(__file__).resolve().parents[1] / 'contracts' / 'openapi.jso
async def lifespan(app: FastAPI):
settings = load_settings()
pool = await open_pool(settings.database_url)
cache = SessionCache(open_cache(settings.redis_url))
try:
await apply_migrations(pool)
app.state.store = Store(pool, settings.session_ttl_seconds)
app.state.store = Store(pool, cache, settings.session_ttl_seconds)
yield
finally:
await pool.close()
try:
await cache.close()
finally:
await pool.close()
def create_app() -> FastAPI: