summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorSebastian Höffner <info@sebastian-hoeffner.de>2021-03-06 01:29:06 +0100
committerGitHub <noreply@github.com>2021-03-05 18:29:06 -0600
commit7632de7c457bebf26b7503c8f7be3693b179b077 (patch)
tree1a07a5e00131f17b76162b770146dfa140e7e367 /README.md
parentf538a49d89c441528973a8aa70b1e6ed3ae10c33 (diff)
downloadrequests-cache-7632de7c457bebf26b7503c8f7be3693b179b077.tar.gz
Add individual expire_after per request. (#177)
* Add individual expire_after per request. This commit adds a new feature to allow individual expire_after times per request. It involves using a custom CachedSession, PerRequestCachedSession, to be used as the session_factory. * Replace deprecated asserts in unit tests Additionally, some sockets are closed even on test failures. This removes some visual clutter when going through the results. * Update docs and README for per-request caching * Remove per_request and integrate behavior into CachedSession * Make test_return_old_data_on_error more reliable This is achieved by using a fixed date and mocking the backend calls to datetime as well. * Adjust per_request cache to new behavior Also adds HTTPBIN_URL environment variable as in test_cache * Add tests for the function determining the expiration datetime * Adjust backend to store expiration dates This also involves slightly different semantics for deletion, but the behavior stays the same. * Minor: black and isort * Update docs for request Add explanation for expire_after special cases, i.e. 'default' and 'cached' and how precedences are handled * Replace assert statements with methods * Remove invalid snippet from README * Remove invalid sentence from docs. * Make expires_before timezone-aware once And combine the checks for expiration * Simplify complexity by removing 'cached' keyword for expire_after
Diffstat (limited to 'README.md')
-rw-r--r--README.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/README.md b/README.md
index 2a10d2e..417eeff 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,25 @@ It can be useful when you are creating some simple data scraper with constantly
changing parsing logic or data format, and don't want to redownload pages or
write complex error handling and persistence.
+For more complex workflows, it is possible to cache different requests with different expiration times, or disable caching for a specific request completely:
+
+
+For more complex workflows, it is possible to cache different requests with different expiry times, or disable caching for a specific request completely:
+
+```python
+import time
+import requests
+import requests_cache
+
+requests_cache.install_cache('demo_cache')
+
+# Hits the URL only 2 times
+for i in range(10):
+ requests.get('http://httpbin.org/delay/1', expire_after=1)
+ time.sleep(0.2)
+```
+
+
## Related Projects
If `requests-cache` isn't quite what you need, you can help make it better! See the
[Contributing Guide](https://github.com/reclosedev/requests-cache/blob/master/CONTRIBUTING.md)