Patcher#
Utilities for patching requests
. See Patching for general usage info.
Warning
These functions are not thread-safe. Use CachedSession
if you want to use
caching in a multi-threaded environment.
Clear the currently installed cache (if any) |
|
Remove responses from the cache according one or more conditions. See :py:meth:`.BaseCache.delete for usage details. |
|
Context manager for temporarily disabling caching for all |
|
Context manager for temporarily enabling caching for all |
|
Get the internal cache object from the currently installed |
|
Install the cache for all |
|
Indicate whether or not requests-cache is currently installed |
|
Remove expired responses from the cache |
|
Disable the cache by restoring the original |
- requests_cache.patcher.delete(*args, **kwargs)[source]#
Remove responses from the cache according one or more conditions. See :py:meth:`.BaseCache.delete for usage details.
- requests_cache.patcher.disabled()[source]#
Context manager for temporarily disabling caching for all
requests
functionsExample
>>> with requests_cache.disabled(): ... requests.get('https://httpbin.org/get')
- requests_cache.patcher.enabled(*args, **kwargs)[source]#
Context manager for temporarily enabling caching for all
requests
functionsExample
>>> with requests_cache.enabled('cache.db'): ... requests.get('https://httpbin.org/get')
Accepts the same arguments as
CachedSession
andinstall_cache()
.
- requests_cache.patcher.get_cache()[source]#
Get the internal cache object from the currently installed
CachedSession
(if any)
- requests_cache.patcher.install_cache(cache_name='http_cache', backend=None, session_factory=<class 'requests_cache.session.CachedSession'>, **kwargs)[source]#
Install the cache for all
requests
functions by monkey-patchingrequests.Session
Example
>>> requests_cache.install_cache('demo_cache')
Accepts all the same parameters as
CachedSession
. Additional parameters:- Parameters:
session_factory (
Type
[Session
]) – Session class to use. It must inherit from eitherCachedSession
orCacheMixin
cache_name (
str
) –
- requests_cache.patcher.is_installed()[source]#
Indicate whether or not requests-cache is currently installed
- Return type:
- requests_cache.patcher.uninstall_cache()[source]#
Disable the cache by restoring the original
requests.Session