()
| 14 | |
| 15 | |
| 16 | def main(): |
| 17 | # The real request will only be made once; afterward, the cached response is used |
| 18 | for _ in range(5): |
| 19 | response = requests.get('https://httpbin.org/get') |
| 20 | |
| 21 | # This is more obvious when calling a slow endpoint |
| 22 | for _ in range(5): |
| 23 | response = requests.get('https://httpbin.org/delay/2') |
| 24 | |
| 25 | # Caching can be disabled if we want to get a fresh page and not cache it |
| 26 | with requests_cache.disabled(): |
| 27 | print(requests.get('https://httpbin.org/ip').text) |
| 28 | |
| 29 | # Get some debugging info about the cache |
| 30 | print(requests_cache.get_cache()) |
| 31 | print('Cached URLS:') |
| 32 | print('\n'.join(requests_cache.get_cache().urls())) |
| 33 | |
| 34 | # Uninstall to remove caching from all requests functions |
| 35 | requests_cache.uninstall_cache() |
| 36 | |
| 37 | |
| 38 | if __name__ == '__main__': |
no test coverage detected
searching dependent graphs…