- Use
Cache-Control
request headers by default - Support
expire_after
param forCachedSession.send()
- Filesystem and SQLite backends: Add better error message if parent path exists but isn't a directory
- Make per-request expiration thread-safe for both
CachedSession.request()
andCachedSession.send()
- Handle some additional corner cases when normalizing request data
- Some micro-optimizations for request matching
- Fix issue with cache headers not being used correctly if
cache_control=True
is used with anexpire_after
value - Support immediate expiration + revalidation for
Cache-Control: max-age=0
andExpires: 0
- Fix license metadata as shown on PyPI
- Redact
ingored_parameters
fromCachedResponse.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
Conditional requests & validation:
- Add support for conditional requests and cache validation using:
ETag
+If-None-Match
headersLast-Modified
+If-Modified-Since
headers304 Not Modified
responses
- 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_dir
wrapper property - Add
FileCache.paths()
method - Add
use_cache_dir
option to use platform-specific user cache directory - Return
pathlib.Path
objects for all file paths - Use shorter hashes for file names
- Add
- SQLite:
- Add
SQLiteCache.db_path
wrapper property - Add
use_memory
option and support for in-memory databases - Add
use_cache_dir
option to use platform-specific user cache directory - Return
pathlib.Path
objects for all file paths
- Add
Serialization:
- Use
cattrs
by default for optimized serialization
Other features:
- 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.Request
instead of just a URL - Allow
create_key()
to optionally accept parameters forrequests.Request
instead of a request object - Allow
match_headers
to optionally accept a list of specific headers to match - Add support for custom cache key callbacks with
key_fn
parameter - By default use blake2 instead of sha256 for generating cache keys
- Slightly reduce size of serialized responses
Backwards-compatible API changes:
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_error
tostale_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_headers
tomatch_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
Dependencies:
- Add
appdirs
as a dependency for easier cross-platform usage of user cache directories - Update
cattrs
from optional to required dependency - Update
itsdangerous
from required to optional (but recommended) dependency - Require
requests
2.22+ andurllib3
1.25.5+
Deprecations & removals:
- Drop support for python 3.6
- Note: python 3.6 support in 0.7.x will continue to be maintained at least until it reaches EOL (2021-12-23)
- Any bugfixes for 0.8 that also apply to 0.7 will be backported
- Remove deprecated
core
module - Remove deprecated
BaseCache.remove_old_entries()
method
- Fix incorrect location of
redirects.sqlite
when using filesystem backend - Fix issue in which
redirects.sqlite
would 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
Expires
headers 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 theextension
parameter.
- 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_key
attribute - Make
CachedResponse
a 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
Backends:
- Add a filesystem backend that stores responses as local files
- SQLite and Filesystem: Add
use_temp
option to store files in a temp directory - SQLite: Use persistent thread-local connections, and improve performance for bulk operations
- DynamoDB: Fix
DynamoDbDict.__iter__
to return keys instead of values - MongoDB: Remove usage of deprecated pymongo
Collection.find_and_modify()
- Allow passing any backend-specific connection kwargs via
CachedSession
to the underlying connection function or object:- SQLite:
sqlite3.connect
- DynamoDB:
boto3.resource
- Redis:
redis.Redis
- MongoDB and GridFS:
pymongo.MongoClient
- SQLite:
Expiration:
- Add optional support for the following request headers:
Cache-Control: max-age
Cache-Control: no-cache
Cache-Control: no-store
- Add optional support for the following response headers:
Cache-Control: max-age
Cache-Control: no-store
Expires
- Add
cache_control
option toCachedSession
to enable usage of cache headers - Add support for HTTP timestamps (RFC 5322) in
expire_after
parameters - Add support for bypassing the cache if
expire_after=0
- Add support for making a cache allowlist using URL patterns
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
Other features:
- requests-cache is now fully typed and PEP-561 compliant
- 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
- Add support for caching multipart form uploads
- Update
BaseCache.urls
to only skip invalid responses, not delete them (for better performance) - Update
ignored_parameters
to 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_error
option to also handle error response codes - Only log request exceptions if
old_data_on_error
is set
Depedencies:
- Add minimum
requests
version of2.17
- Add
attrs
as a dependency for improved serialization models - Add
cattrs
as 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:
- Fix some compatibility issues with
requests 2.17
and2.18
- Run pre-release tests for each supported version of
requests
- Packaging is now handled with 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 on response.request
instead of response
- Fix false positive warning with
include_get_headers
- Fix handling of
decode_content
parameter 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_id
andaws_secret_access_key
kwargs toDynamoDbDict
- Update
GridFSPickleDict.__delitem__
to raise a KeyError for missing items - Demote most
logging.info
statements 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!
Backends:
- SQLite: Allow passing user paths (
~/path-to-cache
) to database file withdb_path
param - SQLite: Add
timeout
parameter - Make default table names consistent across backends (
'http_cache'
)
Expiration:
- Cached responses are now stored with an absolute expiration time, so
CachedSession.expire_after
no longer applies retroactively. To revalidate previously cached items with a new expiration time see below: - Add support for overriding original expiration (i.e., revalidating) 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
(SinceNone
may be ambiguous in some cases)
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
CachedResponse
class to wrap cachedrequests.Response
objects, which makes additional cache information available to client code - Add
CachedHTTPResponse
class to wrapurllib3.response.HTTPResponse
objects, 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.urls
property to get all URLs persisted in the cache - Add optional support for
itsdangerous
for more secure serialization
Other features:
- Add
CacheMixin
class to make the features ofCachedSession
usable as a mixin class, for compatibility with other requests-based libraries. - Add
HEAD
to defaultallowable_methods
Bugfixes:
- Fix caching requests with data specified in
json
parameter - Fix caching requests with
verify
parameter - 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
DbPickleDict
initialization - Fix usage of
CachedSession.cache_disabled
if 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
Depedencies:
- Add
itsdangerous
as a dependency for secure serialization - Add
url-normalize
as a dependency for better request normalization and reducing duplications
Deprecations & removals:
- Drop support for python 2.7, 3.4, and 3.5
- Deprecate
core
module; all imports should be made from top-level package instead- e.g.:
from requests_cache import CachedSession
- Imports
from requests_cache.core
will 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()
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 and Advanced Usage sections.
- Increase test coverage and rewrite most tests using pytest
- Add containerized backends for both local and CI integration testing
- 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 releate issue #68
- Fix ability to pass backend instance in
install_cache
#61
ignore_parameters
feature, 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_after
now also acceptstimedelta
, thanks to @femtotrader- Added Ability to include headers to cache key (
include_get_headers
option) - 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
sqlite
is not available
- Fix
response.from_cache
not set in hooks
- Fix
UnpickleableError
for 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
Requests
1.x.x CachedSession
- Many backward incompatible changes
- Fix broken PyPi package
- Last backward compatible version for
Requests
0.14.2
- Thread safety for default
sqlite
backend - Take into account the POST parameters when cache is configured
with 'POST' in
allowable_methods
- Reduce number of
sqlite
database write operations fast_save
option forsqlite
backend
- Fix: restore responses from response.history
- Internal refactoring (
MemoryCache
->BaseCache
,reduce_response
andrestore_response
moved toBaseCache
) connection
option forMongoCache
- initial PyPI release