diff options
author | Jordan Cook <jordan.cook.git@proton.me> | 2022-10-20 16:01:38 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook.git@proton.me> | 2022-10-26 12:18:22 -0500 |
commit | 75402c5084f02644d8782e0a2a5ea896143e3089 (patch) | |
tree | 8f6251b7368f2fb213a7b8b1a8bda53c76f95a48 | |
parent | 02c49bdf6d45b0a4963b3a55ec7746acd3dccf02 (diff) | |
download | requests-cache-75402c5084f02644d8782e0a2a5ea896143e3089.tar.gz |
Fix backwards-compatibility with deprecated remove_expired_responses
-rw-r--r-- | HISTORY.md | 15 | ||||
-rw-r--r-- | requests_cache/backends/base.py | 4 | ||||
-rw-r--r-- | requests_cache/session.py | 6 |
3 files changed, 17 insertions, 8 deletions
@@ -124,15 +124,16 @@ replacements are listed below: 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 to 1.0, please create a bug report! -* The following undocumented behaviors have been removed: +* The `BaseCache.urls` property has been replaced with a method that returns a list of URLs +* 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. * 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. -* The following is relevant for users who have made **custom backends** that extend built-in storage classes: +* The following is relevant for **custom backends** that extend built-in storage classes: + * All serializer-specific `BaseStorage` subclasses have been removed, and merged into their respective parent classes. This includes `SQLitePickleDict`, `MongoPickleDict`, and `GridFSPickleDict`. * 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 utility module changes: * The `cache_control` module (added in `0.7`) has been split up into multiple modules in a new `policy` subpackage @@ -144,6 +145,14 @@ Backport fixes from 1.0: * Add support for header values as bytes for compatibility with OAuth1 features of `requests-oauthlib` * Update to cattrs 22.2 +Add the following for forwards-compatibility with 1.0: +* `requests_cache.policy` subpackage +* `BaseCache.contains()` +* `BaseCache.delete()` +* `BaseCache.filter()` +* `CachedSession.settings` +* `DeprecationWarning`s to give an earlier notice for upcoming changes in 1.0 + ## 0.9.6 (2022-08-24) Backport fixes from 1.0: * Remove potentially problematic row count from `BaseCache.__str__()` diff --git a/requests_cache/backends/base.py b/requests_cache/backends/base.py index 3afe4e7..67f7832 100644 --- a/requests_cache/backends/base.py +++ b/requests_cache/backends/base.py @@ -185,7 +185,7 @@ class BaseCache: invalid: bool = False, older_than: ExpirationTime = None, ) -> Iterator[CachedResponse]: - """Get responses from the cache, with optional filters + """Get responses from the cache, with optional filters for which responses to include: Args: valid: Include valid and unexpired responses; set to ``False`` to get **only** @@ -298,9 +298,9 @@ class BaseCache: 'please use .delete(expired=True) instead', DeprecationWarning, ) - self.delete(expired=True, invalid=True) if expire_after: self.reset_expiration(expire_after) + self.delete(expired=True, invalid=True) def values(self, check_expiry: bool = False) -> Iterator[CachedResponse]: warn('BaseCache.values() is deprecated; please use .filter() instead', DeprecationWarning) diff --git a/requests_cache/session.py b/requests_cache/session.py index 3ed7a6d..d94adf8 100644 --- a/requests_cache/session.py +++ b/requests_cache/session.py @@ -307,9 +307,9 @@ class CacheMixin(MIXIN_BASE): super().close() self.cache.close() - def remove_expired_responses(self): - """**Deprecated:** Use ``session.cache.delete(expired=True)`` instead""" - self.cache.delete(expired=True, invalid=True) + def remove_expired_responses(self, expire_after: ExpirationTime = None): + # Deprecated; will be replaced by CachedSession.cache.delete(expired=True) + self.cache.remove_expired_responses(expire_after) def __getstate__(self): # Unlike requests.Session, CachedSession may contain backend connection objects that can't |