Add in-memory read cache with CUD-based invalidation
This commit is contained in:
@@ -7,6 +7,7 @@ from app.api.internal_catalog import router as internal_catalog_router
|
||||
from app.api.internal import router as internal_router
|
||||
from app.api.me import router as me_router
|
||||
from app.core.config import get_settings
|
||||
from app.services.runtime_cache import runtime_cache
|
||||
|
||||
app = FastAPI(title="memberapi.ose.tw", version="0.1.0")
|
||||
|
||||
@@ -20,6 +21,18 @@ app.add_middleware(
|
||||
)
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
async def invalidate_runtime_cache_on_cud(request, call_next):
|
||||
response = await call_next(request)
|
||||
if (
|
||||
request.method in {"POST", "PUT", "PATCH", "DELETE"}
|
||||
and request.url.path.startswith(("/admin", "/internal"))
|
||||
and response.status_code < 400
|
||||
):
|
||||
runtime_cache.bump_revision()
|
||||
return response
|
||||
|
||||
|
||||
@app.get("/healthz", tags=["health"])
|
||||
def healthz() -> dict[str, str]:
|
||||
return {"status": "ok"}
|
||||
|
||||
Reference in New Issue
Block a user