Skip to content

Commit 614e0b5

Browse files
committed
Add user-id to fastapi ex.
1 parent e7f9d74 commit 614e0b5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ APP = FastAPI(lifespan=app_setup_teardown)
4646
predicate=lambda x: x.operation == "update",
4747
)
4848
)
49-
async def cached_query() -> dict[str, str]:
49+
async def cached_query(user_id: int) -> dict[str, str]:
5050
"""
5151
Simulates a database query that benefits from cache invalidation.
5252
@@ -59,11 +59,11 @@ async def cached_query() -> dict[str, str]:
5959

6060
# Define a FastAPI route to fetch data, utilizing the cached_query function.
6161
@APP.get("/data")
62-
async def get_data() -> dict:
62+
async def get_data(user_id: int) -> dict:
6363
"""
6464
This endpoint uses the cached_query function to return data, demonstrating
6565
how cache invalidation can be integrated into a web application route.
6666
"""
6767
# Fetch and return the data using the cached query function.
68-
return await cached_query()
68+
return await cached_query(user_id)
6969
```

docs/examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ async def app_setup_teardown(_: FastAPI) -> typing.AsyncGenerator[None, None]:
6565
APP = FastAPI(lifespan=app_setup_teardown)
6666

6767
@decorators.cache(strategy=strategies.Greedy(listener=listener, predicate=lambda x: x.operation == "update"))
68-
async def cached_query() -> dict[str, str]:
68+
async def cached_query(user_id: int) -> dict[str, str]:
6969
return {"data": "query result"}
7070

7171
@APP.get("/data")
72-
async def get_data() -> dict:
73-
return await cached_query()
72+
async def get_data(user_id: int) -> dict:
73+
return await cached_query(user_id)
7474
```

0 commit comments

Comments
 (0)