diff options
| author | Jordan Cook <jordan.cook@pioneer.com> | 2022-03-19 21:50:54 -0500 |
|---|---|---|
| committer | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-01 13:48:25 -0500 |
| commit | 550fca5c604fa9635b19bb4ba10d444e36b30d05 (patch) | |
| tree | 9a6882a7765db1e4201614d171bd3814ef39b39b /docs/user_guide | |
| parent | 5a9a18c7bd1d14812fe6308992a193d4a1479a1e (diff) | |
| download | requests-cache-550fca5c604fa9635b19bb4ba10d444e36b30d05.tar.gz | |
Update docs, doc dependencies, changelog, and contributors
Also:
Restrict redis-py to <4.2, which breaks parameter forwarding on python 3.7 and 3.8
Diffstat (limited to 'docs/user_guide')
| -rw-r--r-- | docs/user_guide/advanced_requests.md | 6 | ||||
| -rw-r--r-- | docs/user_guide/expiration.md | 6 | ||||
| -rw-r--r-- | docs/user_guide/general.md | 30 |
3 files changed, 30 insertions, 12 deletions
diff --git a/docs/user_guide/advanced_requests.md b/docs/user_guide/advanced_requests.md index 1a18939..fcd5a6c 100644 --- a/docs/user_guide/advanced_requests.md +++ b/docs/user_guide/advanced_requests.md @@ -14,7 +14,7 @@ It can be used, for example, for request throttling: >>> import time >>> import requests >>> from requests_cache import CachedSession ->>> + >>> def make_throttle_hook(timeout=1.0): >>> """Make a request hook function that adds a custom delay for non-cached requests""" >>> def hook(response, *args, **kwargs): @@ -23,7 +23,7 @@ It can be used, for example, for request throttling: >>> time.sleep(timeout) >>> return response >>> return hook ->>> + >>> session = CachedSession() >>> session.hooks['response'].append(make_throttle_hook(0.1)) >>> # The first (real) request will have an added delay @@ -42,7 +42,7 @@ the original streamed response: :class: toggle ```python >>> from requests_cache import CachedSession ->>> + >>> session = CachedSession() >>> for i in range(2): ... response = session.get('https://httpbin.org/stream/20', stream=True) diff --git a/docs/user_guide/expiration.md b/docs/user_guide/expiration.md index 5c81ef0..24b9c8a 100644 --- a/docs/user_guide/expiration.md +++ b/docs/user_guide/expiration.md @@ -37,7 +37,7 @@ Examples: >>> session = CachedSession(expire_after=timedelta(days=30)) >>> # Update an existing session to disable expiration (i.e., store indefinitely) ->>> session.expire_after = -1 +>>> session.settings.expire_after = -1 >>> # Disable caching by default, unless enabled by other settings >>> session = CachedSession(expire_after=0) @@ -61,11 +61,11 @@ frequently, another that changes infrequently, and another that never changes. E **Notes:** - `urls_expire_after` should be a dict in the format `{'pattern': expire_after}` -- `expire_after` accepts the same types as `CachedSession.expire_after` +- `expire_after` accepts the same types as `CachedSession.settings.expire_after` - Patterns will match request **base URLs without the protocol**, so the pattern `site.com/resource/` is equivalent to `http*://site.com/resource/**` - If there is more than one match, the first match will be used in the order they are defined -- If no patterns match a request, `CachedSession.expire_after` will be used as a default +- If no patterns match a request, `CachedSession.settings.expire_after` will be used as a default (request-errors)= ## Expiration and Error Handling diff --git a/docs/user_guide/general.md b/docs/user_guide/general.md index 2932a25..7047f04 100644 --- a/docs/user_guide/general.md +++ b/docs/user_guide/general.md @@ -9,7 +9,7 @@ There are two main ways of using requests-cache: Basic usage looks like this: ```python >>> from requests_cache import CachedSession ->>> + >>> session = CachedSession() >>> session.get('http://httpbin.org/get') ``` @@ -41,7 +41,7 @@ cases, you can use {py:func}`.install_cache` to add caching to all `requests` fu ```python >>> import requests >>> import requests_cache ->>> + >>> requests_cache.install_cache() >>> requests.get('http://httpbin.org/get') ``` @@ -81,13 +81,31 @@ requests-cache is currently installed with {py:func}`.is_installed`. (monkeypatch-issues)= ### Patching Limitations & Potential Issues -Like any other utility that uses monkey-patching, there are some scenarios where you won't want to -use {py:func}`.install_cache`: +There are some scenarios where patching `requests` with {py:func}`.install_cache` is not ideal: - When using other libraries that patch {py:class}`requests.Session` - In a multi-threaded or multiprocess application - In a library that will be imported by other libraries or applications - In a larger application that makes requests in several different modules, where it may not be obvious what is and isn't being cached -In any of these cases, consider using {py:class}`.CachedSession`, the {py:func}`.enabled` -contextmanager, or {ref}`selective-caching`. +In these cases, consider using {py:class}`.CachedSession` instead. + +(settings)= +## Settings +There are a number of settings that affect cache behavior, which are covered in more detail in the following sections: +* {ref}`expiration` +* {ref}`filtering` +* {ref}`matching` + +These can all be passed as keyword arguments to {py:class}`.CachedSession` or +{py:func}`.install_cache`. When using a session object, these can also be safely modified at any +time via {py:attr}`.CachedSession.settings`. For example: +```python +>>> from requests_cache import CachedSession + +>>> session = CachedSession() +>>> session.settings.expire_after = 360 +>>> session.settings.stale_if_error = True +``` + +Note that this does **not** include backend and serializer settings, which cannot be changed after initialization. |
