diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-18 16:10:11 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-18 19:50:55 -0500 |
commit | a899d9231c38f11c28b3eb0310022c92d82262b8 (patch) | |
tree | cf09e91629447bbf17fc5ef98f76d1d2866cb1a0 /docs | |
parent | ea326d16d82d86f4fda14f83745a5a399824257d (diff) | |
download | requests-cache-a899d9231c38f11c28b3eb0310022c92d82262b8.tar.gz |
Add support for Cache-Control: stale-if-error
Diffstat (limited to 'docs')
-rw-r--r-- | docs/user_guide/expiration.md | 7 | ||||
-rw-r--r-- | docs/user_guide/headers.md | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/docs/user_guide/expiration.md b/docs/user_guide/expiration.md index 767b220..d0465f1 100644 --- a/docs/user_guide/expiration.md +++ b/docs/user_guide/expiration.md @@ -108,6 +108,13 @@ you get a 500. You will then get the expired cache data instead: True, True ``` +Similar to the header `Cache-Control: stale-if-error`, you may also pass time value representing the +maximum staleness you are willing to accept: +```python +# If there is an error on refresh, use a cached response if it expired 5 minutes ago or less +session = CachedSession(stale_if_error=timedelta(minutes=5)) +``` + In addition to HTTP error codes, `stale_if_error` also applies to python exceptions (typically a {py:exc}`~requests.RequestException`). See `requests` documentation on [Errors and Exceptions](https://2.python-requests.org/en/master/user/quickstart/#errors-and-exceptions) diff --git a/docs/user_guide/headers.md b/docs/user_guide/headers.md index 9681d64..5d7c696 100644 --- a/docs/user_guide/headers.md +++ b/docs/user_guide/headers.md @@ -54,6 +54,8 @@ The following headers are currently supported: - `Cache-Control: no-store`: Skip reading from and writing to the cache - `Cache-Control: only-if-cached`: Only return results from the cache. If not cached, return a 504 response instead of sending a new request. Note that this may return a stale response. +- `Cache-Control: stale-if-error`: If an error occurs while refreshing a cached response, use it + if it expired by no more than this many seconds ago - `If-None-Match`: Automatically added for revalidation, if an `ETag` is available - `If-Modified-Since`: Automatically added for revalidation, if `Last-Modified` is available |