See all unreleased issues and PRs
Expiration & Headers:
Cache-Control: only-if-cachedCache-Control: no-cache request or response headerCache-Control: max-age=0, must-revalidate response headersonly_if_cached option to CachedSession.request() and send() to return only cached results without sending real requestsrefresh option to CachedSession.request() and send() to revalidate with the server before using a cached responseforce_refresh option to CachedSession.request() and send() to awlays make and cache a new request regardless of existing cache contentsexpire_after=0 consistent with Cache-Control: max-age=0: if the response has a validator, save it to the cache but revalidate on use.requests_cache.DO_NOT_CACHE may be used to completely disable caching for a requestBackends:
sorted() method with sorting and other query optionswal parameter to enable write-ahead loggingOther features:
CachedSession.settingsOriginalResponse class, which wraps requests.Response objects and adds type hints for extra cache attributes set on non-cached responses:cache_keycreated_atexpiresfrom_cacheis_expiredcache_key and expires for new (non-cached) responses, if it was written to the cacheCachedSession request methods (get(), post(), etc.)allowable_methods (previously only skipped write)ignored_parameters, to avoid accidentally storing credentials in the cacheDependencies:
appdirs with platformdirsPotentially breaking changes: The following undocumented behaviors have been removed:
match_headers and ignored_parameters must be passed to CachedSession.BaseCache instance.CachedSession backend argument must be either an instance or string alias.CachedSession.settings.CachedSession or BaseCache. In some cases this could silently fail or otherwise have undefined behavior.Internal module changes:
cache_control module have been split up into multiple modules in a new policy subpackagebson and standalone bson codec.CorruptGridFile error in GridFS backend~/...) for SQLite and filesystem backendsparams as a positional argument to CachedSession.request()CachedSession.request(..., expire_after=-1)ForwardRef types during deserialization)See all issues and PRs for 0.9
Expiration & Headers:
Cache-Control request headers by defaultCache-Control: immutableCache-Control: max-age=0 and Expires: 0304 Not Modified response is receivedBackends:
Other features:
expire_after param for CachedSession.send()Performance:
CachedSession.request() and CachedSession.send()Bugfixes:
BaseCache keyword arguments passed along with a backend instancecache_control=True is used with an expire_after valueCachedResponse serialization behavior when using stdlib pickle in a custom serializeringored_parameters from CachedResponse.url (if used for credentials or other sensitive info)DbDict, etc. so fully qualified imports don't breakSee all issues and PRs for 0.8
Expiration & Headers:
ETag + If-None-Match headersLast-Modified + If-Modified-Since headers304 Not Modified responsesBackends:
FileCache.cache_dir wrapper propertyFileCache.paths() methoduse_cache_dir option to use platform-specific user cache directorypathlib.Path objects for all file pathsSQLiteCache.db_path wrapper propertyuse_memory option and support for in-memory databasesuse_cache_dir option to use platform-specific user cache directorypathlib.Path objects for all file pathsSerialization:
cattrs by default for optimized serializationOther features:
BaseCache.update() method as a shortcut for exporting to a different cache instanceBaseCache.has_url() and delete_url() to optionally take parameters for requests.Request instead of just a URLcreate_key() to optionally accept parameters for requests.Request instead of a request objectmatch_headers to optionally accept a list of specific headers to matchkey_fn parameterBackwards-compatible API changes:
The following changes are meant to make certain behaviors more obvious for new users, without breaking existing usage:
Cache-Control: stale-if-error, rename old_data_on_error to stale_if_errorinclude_get_headers to match_headersbackends.sqlite.Db* -> SQLiteCache, SQLiteDict, SQLitePickleDictDependencies:
appdirs as a dependency for easier cross-platform usage of user cache directoriescattrs from optional to required dependencyitsdangerous from required to optional (but recommended) dependencyrequests 2.22+ and urllib3 1.25.5+Deprecations & removals:
core moduleBaseCache.remove_old_entries() methodredirects.sqlite when using filesystem backendredirects.sqlite would get included in response paths with filesystem backendExpires headers not getting converted to UTCDbCache.clear() to succeed even if the database is corruptedDbDict.bulk_delete() to split the operation into multiple statements to support deleting more items than SQLite's variable limit (999).json, .yaml, .pkl, etc.) by default; can be overridden or disabled with the extension parameter.BaseCache.delete_urls() method to bulk delete multiple responses from the cache based on request URLResponse.next (to get the next request in a redirect chain) when 302 responses are cached directlyCachedResponse.cache_key attributeCachedResponse a non-slotted class to allow client code to set arbitrary attributes on itSee all issues and PRs for 0.7
Backends:
use_temp option to store files in a temp directoryDynamoDbDict.__iter__ to return keys instead of valuesCollection.find_and_modify()CachedSession to the underlying connection function or object:sqlite3.connectboto3.resourceredis.Redispymongo.MongoClientExpiration & Headers:
Cache-Control: max-ageCache-Control: no-cacheCache-Control: no-storeCache-Control: max-ageCache-Control: no-storeExpirescache_control option to CachedSession to enable usage of cache headersexpire_after parametersexpire_after=0Serialization:
cattrsultrajsonOther features:
BaseCache.save_response()BaseCache.keys() and values() methodsBaseCache.response_count() method to get an accurate count of responses (excluding invalid and expired)str(CachedResponse)CachedSession, CachedResponse, and BaseCacheBaseCache.urls to only skip invalid responses, not delete them (for better performance)ignored_parameters to also exclude ignored request params, body params, or headers from cached response data (to avoid storing API keys or other credentials)old_data_on_error option to also handle error response codesold_data_on_error is setDepedencies:
requests version of 2.17attrs as a dependency for improved serialization modelscattrs as an optional dependencypip 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 2.17 and 2.18requestsFix a bug in which filter_fn() would get called on response.request instead of response
include_get_headersdecode_content parameter for CachedResponse.raw.read()Collection.count() with estimated_document_count()BaseCache.urlsBaseCache.remove_old_entries() back, as an alias with a DeprecationWarningaws_access_key_id and aws_secret_access_key kwargs to DynamoDbDictGridFSPickleDict.__delitem__ to raise a KeyError for missing itemslogging.info statements to debug levelfind_packages()See all issues and PRs for 0.6
Thanks to Code Shelter and contributors for making this release possible!
Backends:
~/path-to-cache) to database file with db_path paramtimeout parameter'http_cache')Expiration:
CachedSession.expire_after no longer applies retroactively. To reset expiration for previously cached items, see below:CachedSession.remove_expired_responses()datetime-1 (Since None may be ambiguous in some cases)Serialization:
remove_expired_responses(), also remove responses that are invalid due to updated serialization formatCachedResponse class to wrap cached requests.Response objects, which makes additional cache information available to client codeCachedHTTPResponse class to wrap urllib3.response.HTTPResponse objects, available via CachedResponse.rawBaseCache.urls property to get all URLs persisted in the cacheitsdangerous for more secure serializationOther features:
CacheMixin class to make the features of CachedSession usable as a mixin class, for compatibility with other requests-based libraries.HEAD to default allowable_methodsBugfixes:
json parameterverify parametercache_nameDbPickleDict initializationCachedSession.cache_disabled if used within another contextmanagerBaseCacheget_cache(), clear(), and remove_expired_responses() so they will do nothing if requests-cache is not installedsave() methodDepedencies:
itsdangerous as a dependency for secure serializationurl-normalize as a dependency for better request normalization and reducing duplicationsDeprecations & removals:
core module; all imports should be made from top-level package insteadfrom requests_cache import CachedSessionfrom requests_cache.core will raise a DeprecationWarning, and will be removed in a future releaseBaseCache.remove_old_entries() to remove_expired_responses(), to match its wrapper method CachedSession.remove_expired_responses()Docs & Tests:
Project is now added to Code Shelter
install_cache #61ignore_parameters feature, thanks to @themiurgo and @YetAnotherNerd (#52, #55)expire_after now also accepts timedelta, thanks to @femtotraderinclude_get_headers option)CachedSessionsqlite is not availableresponse.from_cache not set in hooksUnpickleableError for gzip responsesrequests_cache.enabled() context managerRequests 1.x.xCachedSessionRequests 0.14.2sqlite backendallowable_methodssqlite database write operationsfast_save option for sqlite backendMemoryCache -> BaseCache, reduce_response and restore_response moved to BaseCache)connection option for MongoCache