diff options
author | Manuel Eggimann <meggimann@iis.ee.ethz.ch> | 2021-11-29 13:50:00 +0100 |
---|---|---|
committer | Manuel Eggimann <meggimann@iis.ee.ethz.ch> | 2021-11-29 13:50:00 +0100 |
commit | ebf04760d14164c86b376e3ba956da00e50efbdc (patch) | |
tree | 2c78e7e078ed6b5cc0cdd842185e36815b594861 | |
parent | 3d5b77e78013d9c08146b94cbbaa5c9a321b9f75 (diff) | |
download | requests-cache-ebf04760d14164c86b376e3ba956da00e50efbdc.tar.gz |
Support saving CachedResponses in base save_response
-rw-r--r-- | requests_cache/backends/base.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/requests_cache/backends/base.py b/requests_cache/backends/base.py index ddd47e7..0096d0f 100644 --- a/requests_cache/backends/base.py +++ b/requests_cache/backends/base.py @@ -92,8 +92,12 @@ class BaseCache: expire_after: Time in seconds until this cache item should expire """ cache_key = cache_key or self.create_key(response.request) - cached_response = CachedResponse.from_response(response, expires=expires) - cached_response = redact_response(cached_response, self.ignored_parameters) + if isinstance(response, CachedResponse): + cached_response = response + cached_response.expires = expires + else: + cached_response = CachedResponse.from_response(response, expires=expires) + cached_response = redact_response(cached_response, self.ignored_parameters) self.responses[cache_key] = cached_response for r in response.history: self.redirects[self.create_key(r.request)] = cache_key |