- If a request contains a header that is in both
ignored_parametersandVary(for example,Authorization+Vary: Authorization), always consider it a cache miss - Ignore + redact some additional common authentication headers + params by default
- Add support for multiple response variations based on
Vary - Fix overwriting headers after revalidation in
read_onlymode - Add tests for python 3.15 (alpha)
- See changes to BSON and JSON serializers below:
๐พ Serialization:
- Significantly reduce the memory usage of JSON serialization
โ ๏ธ serializer='json'will no longer automatically useultrajsonif installed; it must be specified explicitlyโ ๏ธ Drop support for standalonebsoncodec; please installpymongoto use BSON serialization- Remove
[bson]package extra to prevent accidentally installing it in the same environment aspymongo - When using BSON serialization with the filesystem backend, add a
.bsonfile extension by default - Add support for
orjsonas a JSON serializer- However, see https://github.com/ijl/orjson/issues/483 for potential memory issues
- Add the following serializer objects to specify a JSON library:
json_serializer,ujson_serializer, andorjson_serializer - Remove
[json]package extra due to multiple supported JSON libraries - Allow
decode_contentto be set to different values across multiple sessions in use at the same time
๐พ Backends:
- SQLite:
- Use exclusive transaction locks to prevent write contention; replaces retry behavior
- *Filesystem:
- Add {py:class}
requests_cache.backends.filesystem.LRUFileDictclass to optionally limit the size of the filesystem cache. Enabled withmax_cache_bytesargument.
- Add {py:class}
- Redis:
- For maintenance/inspection methods that iterate over the cache, use
SCANandHSCANinstead ofKEYS,HKEYS, andHGETALL
- For maintenance/inspection methods that iterate over the cache, use
- DynamoDB:
- Add optional parameter
create_tableofDynamoDBCacheto control if the class attempts to create the table in DynamoDB or not.
- Add optional parameter
- GridFS:
- Add a
connectionparameter to allow passing an existingMongoClientobject
- Add a
๐ Expiration & headers:
- Add support for
Vary: Cookie
โ๏ธ Session settings:
- Add
autocloseoption to close backend connections when the session is closed - Add
read_onlyoption to read existing cached responses, but not write any new responses to the cache
โน๏ธ Cache convenience methods:
- Add
verifyparameter toBaseCache.contains()anddelete()to handle requests made with SSL verification disabled
๐งฉ Compatibility and packaging:
- Add support for Python 3.13 and 3.14
- Add compatibility with url-normalize 2.0
- Add compatibility with FIPS-compliant systems
- Note: Due to using a different hashing algorithm for cache keys, caches cannot be shared between FIPS- and non-FIPS-compliant systems
- Packaging and project config are now managed by uv
- This has no impact for users; installation from PyPI still works the same
- For developers, see Contributing Guide for details
๐ชฒ Bugfixes:
- Allow
content_root_keysetting to target a sub-tree innormalize_json_body, so only listed fields under that key are ignored in cache keys - Fix
sqlite3.InterfaceError: bad parameter or other API misusewith concurrent SQLite usage in python 3.12+ - Add support for normalizing file-like request bodies
- Ignore and log timezone errors when attempting to reuse responses cached in
requests-cache <= 1.1 - Fix error handling with
stale_if_errorduring revalidation requests - By default, do not automatically close backend connections when using
install_cache() - Fix request headers sent when
expire_afteris set toDO_NOT_CACHE - Show a warning when initializing a cache with both
cache_nameand a backend instance (database names, file paths, etc. cannot be reliably updated after initialization) - When updating response headers after revalidating a cached response, don't set both
Content-LengthandTransfer-Encoding - Treat invalid HTTP dates (eg. 'Expires: 0' and 'Expires: -1') as 'already expired' as per RFC 2616, section 14.21
๐ชฒ Bugfixes:
- Fix
normalize_headersnot accepting header values in bytes - Fix inconsistency due to rounding in
CachedResponse.expires_unixproperty - Fix form boundary used for cached multipart requests to fully comply with RFC 2046
- Fix loading cached JSON content with
decode_content=Truewhen the root element is an empty list or object - Fix usage example with
responseslibrary to be compatible withrequests2.32
- Drop support for python 3.7
- Remove methods deprecated in 1.0 from
CachedSessionandBaseCache
๐ Expiration & headers:
- Add support for
X-HTTP-Method-Overrideand other headers that can override request method
โ๏ธ Session methods:
- Add
CachedSession.wrap()classmethod to add caching to an existingrequests.Sessionobject
๐พ SQLite Backend:
- Add
vacuumparameter toSQLiteCache.delete()to optionally skip vacuuming after deletion (enabled by default to free up disk space) - Optimize
SQLiteCache.delete()when deleting a single key
๐งฉ Compatibility:
- Add support for RFC 7159 JSON body with
decode_content=True(root element with any type) - Use timezone-aware UTC datetimes for all internal expiration values
- Add support for python 3.12
- Note: There is a known bug with multiprocess/multithreaded usage of the SQLite backend on python 3.12.
- Add support for cattrs 23.2
๐ชฒ Bugfixes:
- Fix
IncompleteReaderror that could sometimes occur with streaming requests due to mismatch withContent-Lengthheader - Handle a corner case with streaming requests, conditional requests, and redirects
- When redacting ignored parameters from a cached response, keep the rest of the original URL and headers without normalizing
- Add
CachedHTTPResponse._request_urlproperty for compatibility with urllib3 - Fix form boundary used for cached multipart requests to comply with RFC 2046
- If an explicit CA bundle path is passed via
verifyparam, cache the response under the same key asverify=True - Handle JSON Content-Type charsets and MIME type variations (such as
application/vnd.api+json) during request normalization and serialization
- Backport fix from 1.2: Add compatibility with cattrs 23.2
โ๏ธ Session settings:
- Add support for regular expressions with
urls_expire_after
๐พ SQLite Backend:
- Add
busy_timeoutargument (see SQLite docs for details) - In WAL journaling mode (
wal=True), default to 'normal' synchronous mode instead of 'full' - Fix potential
OperationalError: database is lockedin multithreaded SQLite usage during bulk delete operations - Fix deadlock in multithreaded SQLite usage if a thread encounters an error during COMMIT
๐ชฒ Bugfixes:
- Fix loading cached JSON content with
decode_content=Truewhen the root element is a list - Fix
BaseCache.recreate_keys()to normalize response bodies withb'None' - Fix
BaseCache.contains()for multipart POST requests - Fix
CachedResponse.historynot being fully deserialized on python<=3.8 - Fix request matching with
Varyand redirects - Skip normalizing
CachedResponse.urlso it always matches the original request URL - Avoid unnecessary cache writes for revalidation requests if headers and expiration are unchanged
- Add compatibility with urllib3 2.0
- Ignore
Cache-Control: must-revalidateandno-cacheresponse headers withcache_control=False
See all unreleased issues and PRs
๐ Expiration & headers:
- Add support for
Cache-Control: min-fresh - Add support for
Cache-Control: max-stale - Add support for
Cache-Control: only-if-cached - Add support for
Cache-Control: stale-if-error - Add support for
Cache-Control: stale-while-error - Add support for
Vary - Revalidate for
Cache-Control: no-cacherequest or response header - Revalidate for
Cache-Control: max-age=0, must-revalidateresponse headers - Add an attribute
CachedResponse.revalidatedto indicate if a cached response was revalidated for the current request
โ๏ธ Session settings:
- All settings that affect cache behavior can now be accessed and modified via
CachedSession.settings - Add
always_revalidatesession setting to always revalidate before using a cached response (if a validator is available). - Add
only_if_cachedsession setting to return only cached results without sending real requests - Add
stale_while_revalidatesession setting to return a stale response initially, while a non-blocking request is sent to refresh the response - Make behavior for
stale_if_errorpartially consistent withCache-Control: stale-if-error: Add support for time values (int, timedelta, etc.) in addition toTrue/False
โ๏ธ Request settings:
- Add
only_if_cachedoption toCachedSession.request()andsend()to return only cached results without sending real requests - Add
refreshoption toCachedSession.request()andsend()to revalidate with the server before using a cached response - Add
force_refreshoption toCachedSession.request()andsend()to awlays make and cache a new request regardless of existing cache contents - Make behavior for
expire_after=0consistent withCache-Control: max-age=0: if the response has a validator, save it to the cache but revalidate on use.- The constant
requests_cache.DO_NOT_CACHEmay be used to completely disable caching for a request
- The constant
๐พ Backends:
- DynamoDB:
- For better read performance and usage of read throughput:
- The cache key is now used as the partition key
- Redirects are now cached only in-memory and not persisted
- Cache size (
len()) now uses a fast table estimate instead of a full scan
- Store responses in plain (human-readable) document format instead of fully serialized binary
- 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
- Decode JSON and text response bodies so the saved response can be fully human-readable/editable.
May be disabled with
decode_content=False.
- For better read performance and usage of read throughput:
- Filesystem:
- The default file format has been changed from pickle to JSON
- Decode JSON and text response bodies so the saved response can be fully human-readable/editable.
May be disabled with
decode_content=False.
- MongoDB:
- Store responses in plain (human-readable) document format instead of fully serialized binary
- Add optional integration with MongoDB TTL to improve performance for removing expired responses
- Disabled by default. See 'Backends: MongoDB' docs for details.
- Decode JSON and text response bodies so the saved response can be fully human-readable/editable.
May be disabled with
decode_content=False.
- Redis:
- Add
ttl_offsetargument to add a delay between cache expiration and deletion
- Add
- SQLite:
- Improve performance for removing expired responses with
delete() - Improve performance (slightly) with a large number of threads and high request rate
- Add
count()method to count responses, with option to exclude expired responses (performs a fast indexed count instead of slower in-memory filtering) - Add
size()method to get estimated size of the database (including in-memory databases) - Add
sorted()method with sorting and other query options - Add
walparameter to enable write-ahead logging
- Improve performance for removing expired responses with
- SQLite, Redis, MongoDB, and GridFS:
- Close open database connections when
CachedSessionis used as a contextmanager, or ifCachedSession.close()is called
- Close open database connections when
- 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 in the cache. This will have no effect ifignored_parametersis already set. - Support distinct matching for requests that differ only by a parameter in
ignored_parameters(e.g., for a request sent both with and without authentication) - Support distinct matching for requests that differ only by duplicate request params (e.g,
a=1vs?a=1&a=2)
โน๏ธ Convenience methods:
- Add
expiredandinvalidarguments toBaseCache.delete()(to replaceremove_expired_responses()) - Add
urlsandrequestsarguments toBaseCache.delete()(to replacedelete_url()) - Add
older_thanargument toBaseCache.delete()to delete responses older than a given value - Add
requestsargument toBaseCache.delete()to delete responses matching the given requests - Add
BaseCache.contains()method to check for cached requests either by key or byrequests.Requestobject - Add
urlargument toBaseCache.contains()method (to replacehas_url()) - Add
BaseCache.filter()method to get responses from the cache with various filters - Add
BaseCache.reset_expiration()method to reset expiration for existing responses - Add
BaseCache.recreate_keys()method to recreate cache keys for all previously cached responses (e.g., to preserve cache data after an update that changes request matching behavior) - Update
BaseCache.urlsinto a method that takes optional filter params, and returns sorted unique URLs
โน๏ธ Response attributes and type hints:
- Add
OriginalResponsetype, which adds type hints torequests.Responseobjects for extra attributes added by requests-cache:cache_keycreated_atexpiresfrom_cacheis_expiredrevalidated
OriginalResponse.cache_keyandexpireswill 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.) - Set
CachedResponse.cache_keyattribute for responses read from lower-level storage methods (items(),values(), etc.)
๐งฉ Compatibility fixes:
- PyInstaller: Fix potential
AttributeErrordue to undetected imports when requests-cache is bundled in a PyInstaller package - requests-oauthlib: Add support for header values as bytes for compatibility with OAuth1 features
- redis-py: Fix forwarding connection parameters passed to
RedisCachefor redis-py 4.2 and python <=3.8 - pymongo: Fix forwarding connection parameters passed to
MongoCachefor pymongo 4.1 and python <=3.8 - cattrs: Add compatibility with cattrs 22.2
- python:
- Add tests and support for python 3.11
- Add tests and support for pypy 3.9
๐ชฒ Bugfixes:
- Fix usage of memory backend with
install_cache() - Fix an uncommon
OperationalError: database is lockedin SQLite backend - Fix issue on Windows with occasional missing
CachedResponse.created_attimestamp - Add
CachedRequest.path_urlproperty for compatibility withRequestEncodingMixin - Fix potential
AttributeErrordue to undetected imports when requests-cache is bundled in a PyInstaller package - Fix
AttributeErrorwhen attempting to unpickle aCachedSessionobject, and instead disable pickling by raising aNotImplementedError - Raise an error for invalid expiration string values (except for headers containing httpdates)
- Previously, this would be quietly ignored, and the response would be cached indefinitely
- Fix behavior for
stale_if_errorif an error response code is added toallowable_codes
๐ฆ Dependencies:
- Replace
appdirswithplatformdirs
The following methods are deprecated, and will be removed in 1.2. The recommended replacements are listed below. If this causes problems for you, please open an issue to discuss.
CachedSession.remove_expired_responses():BaseCache.delete(expired=True)BaseCache.remove_expired_responses():BaseCache.delete(expired=True)BaseCache.delete_url():BaseCache.delete(urls=[...])BaseCache.delete_urls():BaseCache.delete(urls=[...])BaseCache.has_key():BaseCache.contains()BaseCache.has_url():BaseCache.contains(url=...)BaseCache.keys():BaseCache.responses.keys()(for all keys), orBaseCache.filter()(for filtering options)BaseCache.values():BaseCache.responses.values()(for all values), orBaseCache.filter()(for filtering options)BaseCache.response_count():len(BaseCache.responses)(for all responses), orBaseCache.filter()(for filtering options)
- After initialization, cache settings can only be accessed and modified via
CachedSession.settings. Previously, some settings could be modified by setting them on eitherCachedSessionorBaseCache. In some cases this could silently fail or otherwise have undefined behavior. BaseCache.urlshas been replaced with a method that returns a list of URLs.- DynamoDB table structure has changed. If you are using the DynamoDB backend, you will need to create a new table when upgrading to 1.0. See DynamoDB backend docs for more details.
Minor breaking changes:
The following changes only affect advanced or undocumented usage, and are not expected to impact most users:
- The arguments
match_headersandignored_parametersmust be passed toCachedSession. Previously, these could also be passed to aBaseCacheinstance. - The
CachedSessionbackendargument must be either an instance or string alias. Previously it would also accept a backend class. - All serializer-specific
BaseStoragesubclasses have been removed, and merged into their respective parent classes. This includesSQLitePickleDict,MongoPickleDict, andGridFSPickleDict.- All
BaseStoragesubclasses now have aserializerattribute, which will be unused if set toNone.
- All
- The
cache_controlmodule (added in0.7) has been split up into multiple modules in a newpolicysubpackage
- Fix
DeprecationWarningraised byBaseCache.urls - Reword ambiguous log message for
BaseCache.delete
Backport fixes from 1.0:
- For custom serializers, handle using a cattrs converter that doesn't support
omit_if_default - Raise an error for invalid expiration string values (except for headers containing httpdates)
Backport compatibility fixes from 1.0:
- PyInstaller: Fix potential
AttributeErrordue to undetected imports when requests-cache is bundled in a PyInstaller package - requests-oauthlib: Add support for header values as bytes for compatibility with OAuth1 features
- cattrs: Add compatibility with cattrs 22.2
- python: Add tests to ensure compatibility with python 3.11
- Fix
AttributeErrorwhen attempting to unpickle aCachedSessionobject, and instead disable pickling by raising aNotImplementedError
Add the following for forwards-compatibility with 1.0:
DeprecationWarningsto give an earlier notice for methods deprecated (not removed) in 1.0requests_cache.policysubpackage (will replacerequests_cache.cache_controlmodule)BaseCache.contains()BaseCache.delete()BaseCache.filter()CachedSession.settings
Backport fixes from 1.0:
- Remove potentially problematic row count from
BaseCache.__str__() - Remove upper version constraints for all non-dev dependencies
- Make dependency specification consistent between PyPI and Conda-Forge packages
Backport fixes from 1.0:
- Fix usage of memory backend with
install_cache() - Add
CachedRequest.path_urlproperty - Add compatibility with cattrs 22.1
Backport fixes from 1.0:
- Fix forwarding connection parameters passed to
RedisCachefor redis-py 4.2 and python <=3.8 - Fix forwarding connection parameters passed to
MongoCachefor pymongo 4.1 and python <=3.8
- Fix handling BSON serializer differences between pymongo's
bsonand standalonebsoncodec. - Handle
CorruptGridFileerror in GridFS backend - Fix cache path expansion for user directories (
~/...) for SQLite and filesystem backends - Fix request normalization for request body with a list as a JSON root
- Skip normalizing a JSON request body if it's excessively large (>10MB) due to performance impact
- Fix some thread safety issues:
- Fix race condition in SQLite backend with dropping and recreating tables in multiple threads
- Fix race condition in filesystem backend when one thread deletes a file after it's opened but before it is read by a different thread
- Fix multiple race conditions in GridFS backend
- Fix serialization in filesystem backend with binary content that is also valid UTF-8
- Fix some regression bugs introduced in 0.9.0:
- Add support for
paramsas a positional argument toCachedSession.request() - Add support for disabling expiration for a single request with
CachedSession.request(..., expire_after=-1)
- Add support for
- Add support for python 3.10.2 and 3.9.10 (regarding resolving
ForwardReftypes during deserialization) - Add support for key-only request parameters (regarding hashing request data for cache key creation)
- Reduce verbosity of log messages when encountering an invalid JSON request body
See all issues and PRs for 0.9
๐ Expiration & headers:
- Use
Cache-Controlrequest headers by default - Add support for
Cache-Control: immutable - Add support for immediate expiration + revalidation with
Cache-Control: max-age=0andExpires: 0 - Reset expiration for cached response when a
304 Not Modifiedresponse is received - Support
expire_afterparam forCachedSession.send()
๐พ Backends:
- Filesystem:
- Add better error message if parent path exists but isn't a directory
- Redis:
- Add optional integration with Redis TTL to improve performance for removing expired responses
- This is enabled by default, but may be disabled
- SQLite:
- Add better error message if parent path exists but isn't a directory
๐ Performance:
- Fix duplicate read operation for checking whether to read from redirects cache
- Skip unnecessary contains check if a key is in the main responses cache
- Make per-request expiration thread-safe for both
CachedSession.request()andCachedSession.send() - Some micro-optimizations for request matching
๐ชฒ Bugfixes:
- Fix regression bug causing headers used for cache key to not guarantee sort order
- Handle some additional corner cases when normalizing request data
- Add support for
BaseCachekeyword arguments passed along with a backend instance - Fix issue with cache headers not being used correctly if
cache_control=Trueis used with anexpire_aftervalue - Fix license metadata as shown on PyPI
- Fix
CachedResponseserialization behavior when using stdlibpicklein a custom serializer
- Redact
ignored_parametersfromCachedResponse.url(if used for credentials or other sensitive info) - Fix an incorrect debug log message about skipping cache write
- Add some additional aliases for
DbDict, etc. so fully qualified imports don't break
See all issues and PRs for 0.8
๐ Expiration & headers:
- Add support for conditional requests and cache validation using:
ETag+If-None-MatchheadersLast-Modified+If-Modified-Sinceheaders304 Not Modifiedresponses
- If a cached response is expired but contains a validator, a conditional request will by sent, and a new response will be cached and returned only if the remote content has not changed
๐พ Backends:
- Filesystem:
- Add
FileCache.cache_dirwrapper property - Add
FileCache.paths()method - Add
use_cache_diroption to use platform-specific user cache directory - Return
pathlib.Pathobjects for all file paths - Use shorter hashes for file names
- Add
- SQLite:
- Add
SQLiteCache.db_pathwrapper property - Add
use_memoryoption and support for in-memory databases - Add
use_cache_diroption to use platform-specific user cache directory - Return
pathlib.Pathobjects for all file paths
- Add
๐ Performance:
- Use
cattrsby default for optimized serialization - Slightly reduce size of serialized responses
- Allow
create_key()to optionally accept parameters forrequests.Requestinstead of a request object - Allow
match_headersto optionally accept a list of specific headers to match - Add support for custom cache key callbacks with
key_fnparameter - By default use blake2 instead of sha256 for generating cache keys
โน๏ธ Cache convenience methods:
- Add
BaseCache.update()method as a shortcut for exporting to a different cache instance - Allow
BaseCache.has_url()anddelete_url()to optionally take parameters forrequests.Requestinstead of just a URL
๐ฆ Dependencies:
- Add
appdirsas a dependency for easier cross-platform usage of user cache directories - Update
cattrsfrom optional to required dependency - Update
itsdangerousfrom required to optional (but recommended) dependency - Require
requests2.22+ andurllib31.25.5+
The following changes are meant to make certain behaviors more obvious for new users, without breaking existing usage:
- For consistency with
Cache-Control: stale-if-error, renameold_data_on_errortostale_if_error- Going forward, any new options based on a standard HTTP caching feature will be named after that feature
- For clarity about matching behavior, rename
include_get_headerstomatch_headers- References in the docs to cache keys and related behavior are now described as 'request matching'
- For consistency with other backends, rename SQLite backend classes:
backends.sqlite.Db*->SQLiteCache,SQLiteDict,SQLitePickleDict - Add aliases for all previous parameter/class names for backwards-compatibility
- Drop support for python 3.6
- Remove deprecated
coremodule - Remove deprecated
BaseCache.remove_old_entries()method
- Fix incorrect location of
redirects.sqlitewhen using filesystem backend - Fix issue in which
redirects.sqlitewould get included in response paths with filesystem backend - Add aliases for forwards-compatibility with 0.8+
- Backport fixes from 0.8.1
- Fix an issue with httpdate strings from
Expiresheaders not getting converted to UTC - Fix a packaging issue with extra files added to top-level wheel directory
- Fix some issues with parallelizing tests using pytest-xdist
- SQLite backend:
- Update
DbCache.clear()to succeed even if the database is corrupted - Update
DbDict.bulk_delete()to split the operation into multiple statements to support deleting more items than SQLite's variable limit (999)
- Update
- Filesystem backend:
- When using JSON serializer, pretty-print JSON by default
- Add an appropriate file extension to cache files (
.json,.yaml,.pkl, etc.) by default; can be overridden or disabled with theextensionparameter.
- Add a
BaseCache.delete_urls()method to bulk delete multiple responses from the cache based on request URL
- Add support for
Response.next(to get the next request in a redirect chain) when 302 responses are cached directly - Add a
CachedResponse.cache_keyattribute - Make
CachedResponsea non-slotted class to allow client code to set arbitrary attributes on it
- Fix a bug in which Cache-Control headers would be used unexpectedly
See all issues and PRs for 0.7
๐ Expiration & headers:
- Add optional support for the following request headers:
Cache-Control: max-ageCache-Control: no-cacheCache-Control: no-store
- Add optional support for the following response headers:
Cache-Control: max-ageCache-Control: no-storeExpires
- Add
cache_controloption toCachedSessionto enable setting expiration with cache headers - Add support for HTTP timestamps (RFC 5322) in
expire_afterparameters - Add support for bypassing the cache if
expire_after=0 - Add support for making a cache allowlist using URL patterns
๐พ Backends:
- Add a filesystem backend that stores responses as local files
- DynamoDB:
- Fix
DynamoDbDict.__iter__to return keys instead of values - Accept connection arguments for
boto3.resource
- Fix
- MongoDB:
- Remove usage of deprecated pymongo
Collection.find_and_modify() - Accept connection arguments for
pymongo.MongoClient
- Remove usage of deprecated pymongo
- Redis:
- Accept connection arguments for
redis.Redis
- Accept connection arguments for
- SQLite:
- Use persistent thread-local connections, and improve performance for bulk operations
- Add
use_tempoption to store files in a temp directory - Accept connection arguments for
sqlite3.connect
๐พ Serialization:
- Add data models for all serialized objects
- Add a JSON serializer
- Add a YAML serializer
- Add a BSON serializer
- Add optional support for
cattrs - Add optional support for
ultrajson
- Add support for caching multipart form uploads
- Update
ignored_parametersto also exclude ignored request params, body params, or headers from cached response data (to avoid storing API keys or other credentials) - Update
old_data_on_erroroption to also handle error response codes - Only log request exceptions if
old_data_on_erroris set
โน๏ธ Convenience methods:
- Add option to manually cache response objects with
BaseCache.save_response() - Add
BaseCache.keys()andvalues()methods - Add
BaseCache.response_count()method to get an accurate count of responses (excluding invalid and expired) - Show summarized response details with
str(CachedResponse) - Add more detailed repr methods for
CachedSession,CachedResponse, andBaseCache - Update
BaseCache.urlsto only skip invalid responses, not delete them (for better performance)
๐ฆ Dependencies:
- Add minimum
requestsversion of2.17 - Add
attrsas a dependency for improved serialization models - Add
cattrsas an optional dependency - Add some package extras to install optional dependencies (via
pip install):requests-cache[all](to install everything)requests-cache[bson]requests-cache[json]requests-cache[dynamodb]requests-cache[mongodb]requests-cache[redis]
๐ฆ Compatibility and packaging:
- requests-cache is now fully typed and PEP-561 compliant
- Fix some compatibility issues with
requests 2.17and2.18 - Run pre-release tests for each supported version of
requests - Packaging is now managed by Poetry
- For users, installation still works the same.
- For developers, see Contributing Guide for details
- Fix a bug in which
filter_fn()would get called onresponse.requestinstead ofresponse
- Fix false positive warning with
include_get_headers - Fix handling of
decode_contentparameter forCachedResponse.raw.read() - Replace deprecated pymongo
Collection.count()withestimated_document_count()
- Explicitly include docs, tests, and examples in sdist
- Handle errors due to invalid responses in
BaseCache.urls - Add recently renamed
BaseCache.remove_old_entries()back, as an alias with a DeprecationWarning - Make parent dirs for new SQLite databases
- Add
aws_access_key_idandaws_secret_access_keykwargs toDynamoDbDict - Update
GridFSPickleDict.__delitem__to raise a KeyError for missing items - Demote most
logging.infostatements to debug level - Exclude test directory from
find_packages() - Make integration tests easier to run and/or fail more quickly in environments where Docker isn't available
See all issues and PRs for 0.6
Thanks to Code Shelter and contributors for making this release possible!
๐ Expiration:
- Cached responses are now stored with an absolute expiration time, so
CachedSession.expire_afterno longer applies retroactively. To reset expiration for previously cached items, see below: - Add support for overriding original expiration in
CachedSession.remove_expired_responses() - Add support for setting expiration for individual requests
- Add support for setting expiration based on URL glob patterns
- Add support for setting expiration as a
datetime - Add support for explicitly disabling expiration with
-1(SinceNonemay be ambiguous in some cases)
๐พ Backends:
- SQLite:
- Allow passing user paths (
~/path-to-cache) to database file withdb_pathparam - Add
timeoutparameter
- Allow passing user paths (
- All: Make default table names consistent across backends (
'http_cache')
๐พ Serialization:
Note: Due to the following changes, responses cached with previous versions of requests-cache will be invalid. These old responses will be treated as expired, and will be refreshed the next time they are requested. They can also be manually converted or removed, if needed (see notes below).
- Add example script to convert an existing cache from previous serialization format to new one
- When running
remove_expired_responses(), also remove responses that are invalid due to updated serialization format - Add
CachedResponseclass to wrap cachedrequests.Responseobjects, which makes additional cache information available to client code - Add
CachedHTTPResponseclass to wrapurllib3.response.HTTPResponseobjects, available viaCachedResponse.raw- Re-construct the raw response on demand to avoid storing extra data in the cache
- Improve emulation of raw request behavior used for iteration, streaming requests, etc.
- Add
BaseCache.urlsproperty to get all URLs persisted in the cache - Add optional support for
itsdangerousfor more secure serialization
Other features:
- Add
CacheMixinclass to make the features ofCachedSessionusable as a mixin class, for compatibility with other requests-based libraries. - Add
HEADto defaultallowable_methods
๐ Docs & Tests:
- Add type annotations to main functions/methods in public API, and include in documentation on readthedocs
- Add Contributing Guide, Security info, and more examples & detailed usage info in User Guide section.
- Increase test coverage and rewrite most tests using pytest
- Add containerized backends for both local and CI integration testing
๐ชฒ Bugfixes:
- Fix caching requests with data specified in
jsonparameter - Fix caching requests with
verifyparameter - Fix duplicate cached responses due to some unhandled variations in URL format
- Fix usage of backend-specific params when used in place of
cache_name - Fix potential TypeError with
DbPickleDictinitialization - Fix usage of
CachedSession.cache_disabledif used within another contextmanager - Fix non-thread-safe iteration in
BaseCache - Fix
get_cache(),clear(), andremove_expired_responses()so they will do nothing if requests-cache is not installed - Update usage of deprecated MongoClient
save()method - Replace some old bugs with new and different bugs, just to keep life interesting
๐ฆ Dependencies:
- Add
itsdangerousas a dependency for secure serialization - Add
url-normalizeas a dependency for better request normalization and reducing duplications
- Drop support for python 2.7, 3.4, and 3.5
- Deprecate
coremodule; all imports should be made from top-level package instead- e.g.:
from requests_cache import CachedSession - Imports
from requests_cache.corewill raise aDeprecationWarning, and will be removed in a future release
- e.g.:
- Rename
BaseCache.remove_old_entries()toremove_expired_responses(), to match its wrapper methodCachedSession.remove_expired_responses()
- Fix DeprecationWarning from collections #140
- Remove Python 2.6 Testing from travis #133
- Fix DeprecationWarning from collections #131
- vacuum the sqlite database after clearing a table #134
- Fix handling of unpickle errors #128
Project is now added to Code Shelter
- Add gridfs support, thanks to @chengguangnan
- Add dynamodb support, thanks to @ar90n
- Add response filter #104, thanks to @christopher-dG
- Fix bulk_commit #78
- Fix remove_expired_responses missed in init.py #93
- Fix deprecation warnings #122, thanks to mbarkhau
- Drop support for python 2.6
- Support PyMongo3, thanks to @craigls #72
- Fix streaming-related issue #68
- Fix ability to pass backend instance in
install_cache#61
ignore_parametersfeature, thanks to @themiurgo and @YetAnotherNerd (#52, #55)- More informative message for missing backend dependencies, thanks to @Garrett-R (#60)
- Better transactional handling in sqlite #50, thanks to @rgant
- Compatibility with streaming in requests >= 2.6.x
expire_afternow also acceptstimedelta, thanks to @femtotrader- Added Ability to include headers to cache key (
include_get_headersoption) - Added string representation for
CachedSession
- Fix bug in reading cached streaming response
- Fix compatibility with Requests > 2.4.1 (json arg, response history)
- Monkey patch now uses class instead lambda (compatibility with rauth)
- Normalize (sort) parameters passed as builtin dict
- Requests==2.3.0 compatibility, thanks to @gwillem
- Check for backend availability in install_cache(), not at the first request
- Default storage fallbacks to memory if
sqliteis not available
- Fix
response.from_cachenot set in hooks
- Fix
UnpickleableErrorfor gzip responses
requests_cache.enabled()context manager- Compatibility with Requests 1.2.3 cookies handling
- Redis backend. Thanks to @michaelbeaumont
- Fix for changes in Requests 1.2.0 hooks dispatching
- Support for
Requests1.x.x CachedSession- Many backward incompatible changes
- Fix broken PyPi package
- Last backward compatible version for
Requests0.14.2
- Thread safety for default
sqlitebackend - Take into account the POST parameters when cache is configured
with 'POST' in
allowable_methods
- Reduce number of
sqlitedatabase write operations fast_saveoption forsqlitebackend
- Fix: restore responses from response.history
- Internal refactoring (
MemoryCache->BaseCache,reduce_responseandrestore_responsemoved toBaseCache) connectionoption forMongoCache
- initial PyPI release