diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-22 17:31:44 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-22 20:27:23 -0500 |
commit | 12b7ebe4ea4a938884b10d8b676c7504b7996017 (patch) | |
tree | 263f322d9eb23c5278e69168220ae2c9e2091de1 | |
parent | 35b48cf3486e546a5e4090e8e410b698e8a6b7be (diff) | |
download | requests-cache-12b7ebe4ea4a938884b10d8b676c7504b7996017.tar.gz |
Update docs and changelog
-rw-r--r-- | HISTORY.md | 39 | ||||
-rw-r--r-- | docs/user_guide/backends/filesystem.md | 14 | ||||
-rw-r--r-- | docs/user_guide/backends/redis.md | 3 | ||||
-rw-r--r-- | docs/user_guide/expiration.md | 6 |
4 files changed, 31 insertions, 31 deletions
@@ -23,6 +23,7 @@ **Backends:** * SQLite: * Improve performance for removing expired items + * Add `size()` method to get estimated size of the database (including in-memory databases) * Add `sorted()` method with sorting and other query options * Add `wal` parameter to enable write-ahead logging * MongoDB: @@ -33,8 +34,15 @@ * Create default table in on-demand mode instead of provisioned * Add optional integration with DynamoDB TTL to improve performance for removing expired responses * This is enabled by default, but may be disabled +* Filesystem: + * The default file format has been changed from pickle to JSON * SQLite, Redis, MongoDB, and GridFS: Close open database connections when `CachedSession` is used as a contextmanager, or if `CachedSession.close()` is called +**Request Matching & Filtering:** +* Add serializer name to cache keys to avoid errors due to switching serializers +* Always skip both cache read and write for requests excluded by `allowable_methods` (previously only skipped write) +* Ignore and redact common authentication headers and request parameters by default. This provides some default recommended values for `ignored_parameters`, to avoid accidentally storing common credentials (e.g., OAuth tokens) in the cache. This will have no effect if you are already setting `ignored_parameters`. + **Type hints:** * Add `OriginalResponse` type, which adds type hints to `requests.Response` objects for extra attributes added by requests-cache: * `cache_key` @@ -45,29 +53,28 @@ * `OriginalResponse.cache_key` and `expires` will be populated for any new response that was written to the cache * Add request wrapper methods with return type hints for all HTTP methods (`CachedSession.get()`, `head()`, etc.) -**Request Matching & Filtering:** -* Add serializer name to cache keys to avoid errors due to switching serializers -* Always skip both cache read and write for requests excluded by `allowable_methods` (previously only skipped write) -* Ignore and redact common authentication params and headers (e.g., for OAuth2) by default - * This is simply a default value for `ignored_parameters`, to avoid accidentally storing credentials in the cache - **Dependencies:** * Replace `appdirs` with `platformdirs` -**Potentially breaking changes:** +**Breaking changes:** +Some relatively minor breaking changes have been made that are not expected to affect most users. +If you encounter a problem not listed here after updating, please file a bug report! + The following undocumented behaviors have been removed: -* The arguments `match_headers` and `ignored_parameters` must be passed to `CachedSession`. - * Previously, these could also be passed to a `BaseCache` instance. -* The `CachedSession` `backend` argument must be either an instance or string alias. - * Previously it would also accept a backend class. +* The arguments `match_headers` and `ignored_parameters` must be passed to `CachedSession`. Previously, these could also be passed to a `BaseCache` instance. +* The `CachedSession` `backend` argument must be either an instance or string alias. Previously it would also accept a backend class. * After initialization, cache settings can only be accesed and modified via - `CachedSession.settings`. - * Previously, some settings could be modified by setting them on either `CachedSession` or `BaseCache`. In some cases this could silently fail or otherwise have undefined behavior. + `CachedSession.settings`. Previously, some settings could be modified by setting them on either `CachedSession` or `BaseCache`. In some cases this could silently fail or otherwise have undefined behavior. + +The following is relevant for users who have made custom backends that extend built-in storage classes: +* All `BaseStorage` subclasses now have a `serializer` attribute, which will be unused if + set to `None`. +* All serializer-specific `BaseStorage` subclasses have been removed, and merged into their respective parent classes. This includes `SQLitePickleDict`, `MongoPickleDict`, and `GridFSPickleDict`. -Internal module changes: -* The contents of the `cache_control` module have been split up into multiple modules in a new `policy` subpackage +Internal utility module changes: +* The `cache_control` module (added in `0.7`) has been split up into multiple modules in a new `policy` subpackage -## 0.9.4 (2022-04-21) +### 0.9.4 (2022-04-22) * Fix forwarding connection parameters passed to `RedisCache` for redis-py 4.2 and python <=3.8 * Fix forwarding connection parameters passed to `MongoCache` for pymongo 4.1 and python <=3.8 diff --git a/docs/user_guide/backends/filesystem.md b/docs/user_guide/backends/filesystem.md index 9fdee7c..07e41c4 100644 --- a/docs/user_guide/backends/filesystem.md +++ b/docs/user_guide/backends/filesystem.md @@ -26,17 +26,9 @@ Or by alias: ``` ## File Formats -By default, responses are saved as pickle files. If you want to save responses in a human-readable -format, you can use one of the other available {ref}`serializers`. For example, to save responses as -JSON files: -```python ->>> session = CachedSession('~/http_cache', backend='filesystem', serializer='json') ->>> session.get('https://httpbin.org/get') ->>> print(list(session.cache.paths())) -> ['/home/user/http_cache/4dc151d95200ec.json'] -``` - -Or as YAML (requires `pyyaml`): +By default, responses are saved as JSON files. If you prefer a deiffernt format, you can use of the +other available {ref}`serializers` or provide your own. For example, to save responses as +YAML files (requires `pyyaml`): ```python >>> session = CachedSession('~/http_cache', backend='filesystem', serializer='yaml') >>> session.get('https://httpbin.org/get') diff --git a/docs/user_guide/backends/redis.md b/docs/user_guide/backends/redis.md index cfe1898..141834c 100644 --- a/docs/user_guide/backends/redis.md +++ b/docs/user_guide/backends/redis.md @@ -47,6 +47,9 @@ or disabled entirely. See [Redis Persistence](https://redis.io/topics/persistenc Redis natively supports TTL on a per-key basis, and can automatically remove expired responses from the cache. This will be set by by default, according to normal {ref}`expiration settings <expiration>`. +Expired items are not removed immediately, but will never be returned from the cache. See +[Redis: EXPIRE](https://redis.io/commands/expire/) docs for more details. + If you intend to reuse expired responses, e.g. with {ref}`conditional-requests` or `stale_if_error`, you can disable this behavior with the `ttl` argument: ```python diff --git a/docs/user_guide/expiration.md b/docs/user_guide/expiration.md index d0465f1..a53da87 100644 --- a/docs/user_guide/expiration.md +++ b/docs/user_guide/expiration.md @@ -142,15 +142,13 @@ You can also apply a new `expire_after` value to previously cached responses: >>> session.remove_expired_responses(expire_after=timedelta(days=30)) ``` +(ttl)= ### Automatic Removal The following backends have native TTL support, which can be used to automatically remove expired responses: +* {py:mod}`DynamoDB <requests_cache.backends.dynamodb>` * {py:mod}`MongoDB <requests_cache.backends.mongodb>` * {py:mod}`Redis <requests_cache.backends.redis>` -<!-- -TODO: Not yet supported: -* {py:mod}`DynamoDB <requests_cache.backends.dynamodb>` ---> ## Request Options In addition to the base arguments for {py:func}`requests.request`, requests-cache adds some extra |