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-8/

HTTP Response Cache Manager

Build a persistent HTTP cache system that stores API responses to disk and retrieves them on subsequent requests.

Requirements

Your system should:

  1. Create a persistent cache that stores HTTP responses to a local database file
  2. Make HTTP GET requests to retrieve JSON data from a public API endpoint
  3. Store complete response objects in the cache so they can be retrieved later
  4. Return cached responses for identical requests without making new network calls
  5. Ensure the cache persists between program executions

Implementation Details

  • Use https://httpbin.org/json as your test API endpoint
  • Store the cache in a file named http_cache.db in the current directory
  • Make the same request twice to demonstrate caching behavior
  • Print a message indicating whether each response came from cache or network

Test Cases

Your implementation must handle these scenarios:

  • First request to an endpoint fetches from network and stores in cache @test
  • Second identical request returns cached response without network call @test
  • Cache persists after program restart and previously cached data remains available @test

Deliverables

Create a Python script cache_manager.py that demonstrates the caching functionality described above.

@generates

API

def fetch_with_cache(url: str, cache_file: str = "http_cache.db") -> dict:
    """
    Fetch data from URL using persistent cache.

    Args:
        url: The URL to fetch
        cache_file: Path to the cache database file

    Returns:
        dict: The JSON response data
    """
    pass

def is_response_cached(url: str, cache_file: str = "http_cache.db") -> bool:
    """
    Check if a URL's response is in the cache.

    Args:
        url: The URL to check
        cache_file: Path to the cache database file

    Returns:
        bool: True if cached, False otherwise
    """
    pass

Dependencies { .dependencies }

requests-cache { .dependency }

Provides HTTP caching with persistent storage and automatic serialization support.

Version

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