Skip to content

Commit 43299f7

Browse files
committed
Support s-maxage pragma
1 parent 7b1f266 commit 43299f7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

httpx_caching/_policy.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,12 @@ def try_from_cache_policy(
222222
# determine freshness
223223
freshness_lifetime = 0
224224

225+
# Check the s-maxage pragma in the cache control header
226+
if "s-maxage" in resp_cc:
227+
freshness_lifetime = resp_cc["s-maxage"]
228+
logger.debug("Freshness lifetime from s-maxage: %i", freshness_lifetime)
225229
# Check the max-age pragma in the cache control header
226-
if "max-age" in resp_cc:
230+
elif "max-age" in resp_cc:
227231
freshness_lifetime = resp_cc["max-age"]
228232
logger.debug("Freshness lifetime from max-age: %i", freshness_lifetime)
229233
# If there isn't a max-age, check for an expires header
@@ -427,8 +431,10 @@ def cache_response_action(
427431
# is no date header then we can't do anything about expiring
428432
# the cache.
429433
elif "date" in server_response.headers:
430-
# cache when there is a max-age > 0
431-
if "max-age" in cc and cc["max-age"] > 0:
434+
# cache when there is a s-maxage or max-age > 0
435+
if "s-maxage" in cc and cc["s-maxage"] > 0:
436+
logger.debug("Caching b/c date exists and s-maxage > 0")
437+
elif "max-age" in cc and cc["max-age"] > 0:
432438
logger.debug("Caching b/c date exists and max-age > 0")
433439

434440
# If the request can expire, it means we should cache it

0 commit comments

Comments
 (0)