Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Ramsay <[email protected]>
  • Loading branch information
seapagan committed Apr 6, 2024
1 parent 2a4c0cb commit f3efb43
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions fastapi_redis_cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async def inner_wrapper(
request = func_kwargs.pop("request", None)
response = func_kwargs.pop("response", None)
create_response_directly = not response

if create_response_directly:
response = Response()
# below fix by @jaepetto on the original repo.
Expand Down Expand Up @@ -149,6 +150,8 @@ async def inner_wrapper(
**kwargs: Any, # noqa: ANN401
) -> Any: # noqa: ANN401
"""Invalidate all cached responses with the same tag."""
_headers = kwargs.get("request", None).headers

redis_cache = FastApiRedisCache()
orig_response = await get_api_response_async(func, *args, **kwargs)

Expand Down
6 changes: 4 additions & 2 deletions tests/live_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def cache_invalid_type(request: Request, response: Response) -> logging.Logger:

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

@app.put("/cache_with_args/{user}")
@expires(tag="user_tag")
def put_cache_with_args(user: int) -> dict[str, Union[bool, str]]:
def put_cache_with_args(
user: int, request: Request
) -> dict[str, Union[bool, str]]:
"""Put request to change data for a specific user."""
return {
"success": True,
Expand Down

0 comments on commit f3efb43

Please sign in to comment.