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 simple HTTP caching utility that allows configuring cache expiration times both at the session level and on a per-request basis.
Create a utility that:
@generates
"""HTTP caching utility with per-request expiration control."""
from datetime import timedelta
from typing import Union, Optional
def create_cache_session(default_expiration: Union[int, timedelta]) -> object:
"""
Create a new HTTP caching session with a default expiration time.
Args:
default_expiration: Default time for cached responses to remain valid.
Can be an integer (seconds) or timedelta object.
Returns:
A session object that supports making cached HTTP requests.
"""
pass
def make_request(session: object, url: str, expiration: Optional[Union[int, timedelta]] = None) -> object:
"""
Make an HTTP GET request using the provided session.
Args:
session: The caching session to use for the request.
url: The URL to request.
expiration: Optional expiration override for this specific request.
If not provided, uses the session's default expiration.
Can be an integer (seconds), timedelta, or special value.
Returns:
The response object from the HTTP request.
"""
pass
def is_cached(session: object, url: str) -> bool:
"""
Check if a URL is currently cached in the session.
Args:
session: The caching session to check.
url: The URL to check for in the cache.
Returns:
True if the URL is cached and not expired, False otherwise.
"""
passProvides persistent HTTP caching for Python requests.
@satisfied-by