Skip to content

Commit 84b3f9e

Browse files
committed
wip
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
1 parent 80cad0a commit 84b3f9e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

fastapi_redis_cache/cache.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ async def inner_wrapper(
5454
request = func_kwargs.pop("request", None)
5555
response = func_kwargs.pop("response", None)
5656
create_response_directly = not response
57+
5758
if create_response_directly:
5859
response = Response()
5960
# below fix by @jaepetto on the original repo.
@@ -149,6 +150,8 @@ async def inner_wrapper(
149150
**kwargs: Any, # noqa: ANN401
150151
) -> Any: # noqa: ANN401
151152
"""Invalidate all cached responses with the same tag."""
153+
_headers = kwargs.get("request", None).headers
154+
152155
redis_cache = FastApiRedisCache()
153156
orig_response = await get_api_response_async(func, *args, **kwargs)
154157

tests/live_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def cache_invalid_type(request: Request, response: Response) -> logging.Logger:
9999

100100
@app.get("/cache_with_args/{user}")
101101
@cache_one_hour(tag="user_tag")
102-
def cache_with_args(user: int) -> dict[str, Union[bool, str]]:
102+
def cache_with_args(user: int, request: Request) -> dict[str, Union[bool, str]]:
103103
"""Have a varying cache key based on the user argument."""
104104
return {
105105
"success": True,
@@ -109,7 +109,9 @@ def cache_with_args(user: int) -> dict[str, Union[bool, str]]:
109109

110110
@app.put("/cache_with_args/{user}")
111111
@expires(tag="user_tag")
112-
def put_cache_with_args(user: int) -> dict[str, Union[bool, str]]:
112+
def put_cache_with_args(
113+
user: int, request: Request
114+
) -> dict[str, Union[bool, str]]:
113115
"""Put request to change data for a specific user."""
114116
return {
115117
"success": True,

0 commit comments

Comments
 (0)