Files
lta_datamall_api/app/main.py
T
furyhawk f10ab4e7b3 Implement Valkey caching layer and update related configurations
- Add CacheClient for managing Valkey interactions
- Integrate caching into bus API routes for improved performance
- Update .env.example and config.py for Valkey settings
- Modify Makefile and README for Valkey service management
- Add Valkey service to docker-compose
- Include Valkey dependency in pyproject.toml and uv.lock
2026-05-31 10:53:14 +08:00

42 lines
957 B
Python

from contextlib import asynccontextmanager
from fastapi import FastAPI
from app.api.routes import bus, health
from app.core.config import get_settings
from app.services.cache import CacheClient
from app.services.lta_client import LTAClient
@asynccontextmanager
async def lifespan(app: FastAPI):
settings = get_settings()
lta_client = LTAClient(settings)
cache_client = CacheClient(settings)
await lta_client.startup()
await cache_client.startup()
app.state.lta_client = lta_client
app.state.cache_client = cache_client
yield
await lta_client.shutdown()
await cache_client.shutdown()
def create_app() -> FastAPI:
settings = get_settings()
app = FastAPI(
title=settings.app_name,
version=settings.app_version,
debug=settings.app_debug,
lifespan=lifespan,
)
app.include_router(health.router)
app.include_router(bus.router)
return app
app = create_app()