tessl install tessl/pypi-requests-cache@1.2.0A persistent cache for python requests
Agent Success
Agent success rate when using this tile
76%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.27x
Baseline
Agent success rate without this tile
60%
Build a tool that fetches URLs and tracks complete redirect chains using caching to improve performance and enable offline access to redirect history.
Your implementation should:
Fetch URLs with redirect tracking: Make HTTP requests that follow redirects and preserve the complete chain of redirects for each request.
Cache responses with redirect history: Store responses in a persistent cache so that the complete redirect chain is preserved across program executions.
Access any URL in the chain: When a URL from a previously cached redirect chain is requested again, the system should return the cached final response without making a new HTTP request.
Display redirect information: Provide functionality to display the complete redirect chain for a cached URL, including:
Persistence: The cache should persist to disk using SQLite storage so redirect history is available across program runs.
@generates
You should implement a Python module that provides:
def fetch_url(url: str) -> dict:
"""
Fetch a URL with caching enabled. Follow redirects and preserve the complete chain.
Args:
url: The URL to fetch
Returns:
A dictionary containing:
- 'final_url': The final URL after all redirects
- 'status_code': The final response status code
- 'redirect_count': Number of redirects encountered
"""
pass
def get_redirect_chain(url: str) -> list:
"""
Retrieve the redirect chain for a cached URL.
Args:
url: Any URL that was part of a redirect chain (initial URL, intermediate, or final)
Returns:
A list of dictionaries, each containing:
- 'url': The URL at this step
- 'status_code': The HTTP status code
Returns an empty list if the URL is not in the cache.
"""
passFetching a URL that redirects (http://httpbin.org/redirect/2) should follow the redirects and return the final destination URL. @test
After caching a redirect chain, requesting any intermediate URL from that chain should return the cached final response without making a new HTTP request. @test
The get_redirect_chain function should return the complete redirect history including all intermediate URLs and their status codes. @test
Cache data should persist across program restarts - fetching the same URL after restarting should use the cached response. @test
Provides persistent HTTP caching with redirect history support.