@@ -280,7 +280,7 @@ def cache_response(self, request, response, body=None, status_codes=None):
280
280
cc = self .parse_cache_control (response_headers )
281
281
282
282
cache_url = self .cache_url (request .url )
283
- logger .debug ('Updating cache %r with response from "%s"' , self . cache , cache_url )
283
+ logger .debug ('Updating cache with response from "%s"' , cache_url )
284
284
285
285
# Delete it from the cache if we happen to have it stored there
286
286
no_store = False
@@ -309,14 +309,14 @@ def cache_response(self, request, response, body=None, status_codes=None):
309
309
if self .cache_etags and "etag" in response_headers :
310
310
logger .debug ("Caching due to etag" )
311
311
self .cache .set (
312
- cache_url , self .serializer .dumps (request , response , body = body )
312
+ cache_url , self .serializer .dumps (request , response , body )
313
313
)
314
314
315
315
# Add to the cache any permanent redirects. We do this before looking
316
316
# that the Date headers.
317
317
elif int (response .status ) in PERMANENT_REDIRECT_STATUSES :
318
318
logger .debug ("Caching permanent redirect" )
319
- self .cache .set (cache_url , self .serializer .dumps (request , response ))
319
+ self .cache .set (cache_url , self .serializer .dumps (request , response , b'' ))
320
320
321
321
# Add to the cache if the response headers demand it. If there
322
322
# is no date header then we can't do anything about expiring
@@ -329,7 +329,7 @@ def cache_response(self, request, response, body=None, status_codes=None):
329
329
if "max-age" in cc and cc ["max-age" ] > 0 :
330
330
logger .debug ("Caching b/c date exists and max-age > 0" )
331
331
self .cache .set (
332
- cache_url , self .serializer .dumps (request , response , body = body )
332
+ cache_url , self .serializer .dumps (request , response , body )
333
333
)
334
334
335
335
# If the request can expire, it means we should cache it
@@ -338,7 +338,7 @@ def cache_response(self, request, response, body=None, status_codes=None):
338
338
if response_headers ["expires" ]:
339
339
logger .debug ("Caching b/c of expires header" )
340
340
self .cache .set (
341
- cache_url , self .serializer .dumps (request , response , body = body )
341
+ cache_url , self .serializer .dumps (request , response , body )
342
342
)
343
343
else :
344
344
logger .debug ("No combination of headers to cache." )
@@ -379,6 +379,7 @@ def update_cached_response(self, request, response):
379
379
cached_response .status = 200
380
380
381
381
# update our cache
382
- self .cache .set (cache_url , self .serializer .dumps (request , cached_response ))
382
+ body = cached_response .read (decode_content = False )
383
+ self .cache .set (cache_url , self .serializer .dumps (request , cached_response , body ))
383
384
384
385
return cached_response
0 commit comments