Skip to content

Instantly share code, notes, and snippets.

@fsschmitt
Created September 19, 2018 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsschmitt/6e7cc9327a6999b93c51608e529d9400 to your computer and use it in GitHub Desktop.
Save fsschmitt/6e7cc9327a6999b93c51608e529d9400 to your computer and use it in GitHub Desktop.
Python's requests_cache library example
import time
import requests
import requests_cache
requests_cache.install_cache('tmp/demo_cache', expire_after=120)
start_time = time.time()
for i in range(10):
r = requests.get('http://httpbin.org/delay/1?index={}'.format(i))
print("Request {}{}: {}".format(i+1," (from cache)" if r.from_cache else " (live)",r.text))
print("--- %s seconds ---" % (time.time() - start_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment