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 weather data caching system that uses Redis as the storage backend to cache HTTP responses from a weather API.
Your system should:
@generates
def create_weather_session(redis_host: str = 'localhost', redis_port: int = 6379) -> CachedSession:
"""
Create a cached session configured with Redis backend.
Parameters:
- redis_host: Redis server hostname
- redis_port: Redis server port number
Returns:
CachedSession configured with Redis backend and default expiration
"""
def fetch_current_weather(session: CachedSession, city: str) -> dict:
"""
Fetch current weather data for a city with 5-minute cache expiration.
Parameters:
- session: CachedSession instance
- city: City name
Returns:
Weather data dictionary
"""
def fetch_weekly_forecast(session: CachedSession, city: str) -> dict:
"""
Fetch weekly forecast data for a city with 1-hour cache expiration.
Parameters:
- session: CachedSession instance
- city: City name
Returns:
Forecast data dictionary
"""
def clear_weather_cache(session: CachedSession) -> None:
"""
Clear all cached weather data.
Parameters:
- session: CachedSession instance
"""
def is_cached(session: CachedSession, url: str) -> bool:
"""
Check if a URL is cached.
Parameters:
- session: CachedSession instance
- url: URL to check
Returns:
True if URL is cached, False otherwise
"""Provides HTTP caching with Redis storage backend and expiration control.
@satisfied-by
Python Redis client for Redis server connectivity.
@satisfied-by