summaryrefslogtreecommitdiff
path: root/requests_cache
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2021-07-09 20:06:24 -0500
committerJordan Cook <jordan.cook@pioneer.com>2021-07-09 20:06:29 -0500
commitb4766ff2c2b5c6cf637cac163b39d7adc499faaa (patch)
treead3f7f5768b9dcc8144d6b9593d535e3122342f1 /requests_cache
parent1c8cc1fb3314fa87c9f083e706958d5c73a968bd (diff)
downloadrequests-cache-b4766ff2c2b5c6cf637cac163b39d7adc499faaa.tar.gz
Fix cache_control option to correctly toggle cache header usage (off by default)
Diffstat (limited to 'requests_cache')
-rw-r--r--requests_cache/cache_control.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/requests_cache/cache_control.py b/requests_cache/cache_control.py
index bc9fb5c..978ec0f 100644
--- a/requests_cache/cache_control.py
+++ b/requests_cache/cache_control.py
@@ -50,6 +50,7 @@ class CacheActions:
):
"""Initialize from request info and cache settings"""
self.key = key
+ self.cache_control = cache_control
if cache_control and has_cache_headers(request.headers):
self._init_from_headers(request.headers)
else:
@@ -91,11 +92,19 @@ class CacheActions:
def update_from_response(self, response: Response):
"""Update expiration + actions based on response headers, if not previously set by request"""
+ if not self.cache_control:
+ return
directives = get_cache_directives(response.headers)
do_not_cache = directives.get('max-age') == DO_NOT_CACHE
self.expire_after = coalesce(self.expires, directives.get('max-age'), directives.get('expires'))
self.skip_write = self.skip_write or do_not_cache or 'no-store' in directives
+ def __str__(self):
+ return (
+ f'Expire after: {self.expire_after} | Skip read: {self.skip_read} | '
+ f'Skip write: {self.skip_write}'
+ )
+
def coalesce(*values: Any, default=None) -> Any:
"""Get the first non-``None`` value in a list of values"""