From af9c4d4c56c3654526d2d9cd0a45c62b0a3710e4 Mon Sep 17 00:00:00 2001 From: "Charl P. Botha" Date: Fri, 14 Oct 2022 13:44:59 +0200 Subject: [PATCH] Restore demo of sync handling --- examples/redis/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/redis/main.py b/examples/redis/main.py index 9c51d15..0a62277 100644 --- a/examples/redis/main.py +++ b/examples/redis/main.py @@ -41,11 +41,13 @@ async def get_data(request: Request, response: Response): return pendulum.today() +# Note: This function MUST be sync to demonstrate fastapi-cache's correct handling, +# i.e. running cached sync functions in threadpool just like FastAPI itself! @app.get("/blocking") @cache(namespace="test", expire=10) -async def blocking(): +def blocking(): time.sleep(5) - return dict(ret=await get_ret()) + return dict(ret=get_ret()) @app.get("/datetime")