CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-requests-cache

tessl install tessl/pypi-requests-cache@1.2.0

A 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%

task.mdevals/scenario-3/

Weather API Cache with Redis

Build a simple weather data caching system that uses Redis as the storage backend to cache HTTP responses from a weather API.

Requirements

Your system should:

  1. Cache weather API responses using Redis storage backend
  2. Set different expiration times based on data type:
    • Current weather data expires after 5 minutes
    • Weekly forecast data expires after 1 hour
  3. Use appropriate Redis connection configuration with host and port parameters
  4. Verify that cached responses are properly stored and retrieved from Redis
  5. Clear the cache when requested

Implementation

@generates

API

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
    """

Test Cases

Redis Backend Configuration

  • Creating a session with Redis backend successfully initializes with custom host and port @test
  • Session uses 'redis' as the backend type @test

Cache Expiration

  • Current weather requests are cached with 5-minute (300 seconds) expiration @test
  • Weekly forecast requests are cached with 1-hour (3600 seconds) expiration @test

Cache Operations

  • Fetching the same current weather twice returns cached response on second request @test
  • Cache can be cleared and subsequent requests create new cache entries @test
  • The is_cached function correctly identifies cached URLs @test

Dependencies { .dependencies }

requests-cache { .dependency }

Provides HTTP caching with Redis storage backend and expiration control.

@satisfied-by

redis { .dependency }

Python Redis client for Redis server connectivity.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/requests-cache@1.2.x
tile.json