When making HTTP requests in Python using the popular requests library, you may notice that subsequent requests to the same URL are faster. This speedup is due to caching.
Under the hood,
This means that instead of re-doing DNS lookups, setting up new TLS connections, and re-authenticating on every request,
Here's a quick example:
import requests
start = time.perf_counter()
resp = requests.get('https://example.com/')
end = time.perf_counter()
print(f"Initial request took {end - start:.2f} seconds")
start = time.perf_counter()
resp = requests.get('https://example.com/')
end = time.perf_counter()
print(f"Subsequent request took {end - start:.2f} seconds")
On the initial request, we time how long it takes to resolve DNS, establish a TLS connection, send the request, and get the response. On the second request, all that cached info is re-used, so it should be much faster!
The ability for