summaryrefslogtreecommitdiff
path: root/requests_cache/cache_control.py
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2021-10-23 11:33:13 -0500
committerJordan Cook <jordan.cook@pioneer.com>2021-10-23 11:36:02 -0500
commit0b8a8bb1220310cdc6be3d350caf9fbb65b402fb (patch)
tree85443bac60fb0a5568cbdd4858b730c9c199d25b /requests_cache/cache_control.py
parente311f9acc2f20718d7aa1b86e544554f572671f9 (diff)
downloadrequests-cache-0b8a8bb1220310cdc6be3d350caf9fbb65b402fb.tar.gz
Add support for Cache-Control: immutable
Diffstat (limited to 'requests_cache/cache_control.py')
-rw-r--r--requests_cache/cache_control.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/requests_cache/cache_control.py b/requests_cache/cache_control.py
index 604820f..5b238d8 100644
--- a/requests_cache/cache_control.py
+++ b/requests_cache/cache_control.py
@@ -28,7 +28,7 @@ __all__ = ['DO_NOT_CACHE', 'CacheActions']
# May be set by either headers or expire_after param to disable caching
DO_NOT_CACHE = 0
# Supported Cache-Control directives
-CACHE_DIRECTIVES = ['max-age', 'no-cache', 'no-store']
+CACHE_DIRECTIVES = ['immutable', 'max-age', 'no-cache', 'no-store']
CacheDirective = Tuple[str, Union[None, int, bool]]
ExpirationTime = Union[None, int, float, str, datetime, timedelta]
@@ -136,9 +136,12 @@ class CacheActions:
logger.debug(f'Cache directives from response headers: {directives}')
# Check headers for expiration, validators, and other cache directives
- self.expire_after = coalesce(
- directives.get('max-age'), directives.get('expires'), self.expire_after
- )
+ if directives.get('immutable'):
+ self.expire_after = -1
+ else:
+ self.expire_after = coalesce(
+ directives.get('max-age'), directives.get('expires'), self.expire_after
+ )
has_validator = response.headers.get('ETag') or response.headers.get('Last-Modified')
no_store = 'no-store' in directives or 'no-store' in self.request_directives