@@ -46,14 +46,24 @@ async def inner_wrapper(*args, **kwargs):
46
46
key = redis_cache .get_cache_key (func , * args , ** kwargs )
47
47
ttl , in_cache = redis_cache .check_cache (key )
48
48
if in_cache :
49
+ redis_cache .set_response_headers (response , True , deserialize_json (in_cache ), ttl )
49
50
if redis_cache .requested_resource_not_modified (request , in_cache ):
50
51
response .status_code = int (HTTPStatus .NOT_MODIFIED )
51
- return response
52
- cached_data = deserialize_json (in_cache )
53
- redis_cache .set_response_headers (response , cache_hit = True , response_data = cached_data , ttl = ttl )
54
- if create_response_directly :
55
- return Response (content = in_cache , media_type = "application/json" , headers = response .headers )
56
- return cached_data
52
+ return (
53
+ Response (
54
+ content = None ,
55
+ status_code = response .status_code ,
56
+ media_type = "application/json" ,
57
+ headers = response .headers ,
58
+ )
59
+ if create_response_directly
60
+ else response
61
+ )
62
+ return (
63
+ Response (content = in_cache , media_type = "application/json" , headers = response .headers )
64
+ if create_response_directly
65
+ else deserialize_json (in_cache )
66
+ )
57
67
response_data = await get_api_response_async (func , * args , ** kwargs )
58
68
ttl = calculate_ttl (expire )
59
69
cached = redis_cache .add_to_cache (key , response_data , ttl )
0 commit comments