or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/hishel@0.1.x
tile.json

tessl/pypi-hishel

tessl install tessl/pypi-hishel@0.1.0

Persistent cache implementation for httpx and httpcore following RFC 9111 specification

Agent Success

Agent success rate when using this tile

74%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.48x

Baseline

Agent success rate without this tile

50%

task.mdevals/scenario-5/

HTTP Cache State Tracker

A diagnostic tool that monitors and reports on HTTP caching behavior by tracking cache state transitions and operations.

Problem Description

Build a cache state tracking system that wraps an HTTP client with caching capabilities and provides detailed insights into caching operations. The system should track when responses are served from cache, when cache misses occur, when revalidation happens, and when responses are stored.

Your implementation should handle multiple caching scenarios including fresh cache hits, cache misses, stale response revalidation, and responses that cannot be cached.

Requirements

Core Functionality

The system must provide:

  1. An HTTP client wrapper with built-in caching support that can make GET requests
  2. State tracking that captures cache operations (hits, misses, stores, revalidations)
  3. A reporting interface that returns cache statistics including:
    • Total requests made
    • Number of cache hits (responses served from cache)
    • Number of cache misses (requests that went to origin)
    • Number of revalidations (stale responses that required checking with origin)
    • Number of responses stored in cache

Behavior Specifications

  • When a request is made for the first time, it should result in a cache miss and the response should be stored if cacheable
  • When a subsequent request is made for a cached resource with fresh content, it should result in a cache hit
  • When a cached resource becomes stale but has revalidation headers, the system should perform revalidation
  • The system should correctly identify and track when responses cannot be cached (e.g., no-store directive)
  • Statistics should accurately reflect the cumulative behavior across multiple requests

Test Cases

Fresh Cache Hit

  • Making two identical requests to a cacheable endpoint results in one cache miss and one cache hit @test

Cache Miss and Store

  • The first request to any endpoint results in a cache miss, and if cacheable, the response is stored @test

Revalidation Tracking

  • When accessing a stale cached resource that supports revalidation, the system tracks it as a revalidation operation @test

Implementation

@generates

API

class CacheStateTracker:
    """
    Tracks HTTP caching state transitions and operations.
    """

    def __init__(self, base_url: str):
        """
        Initialize the cache state tracker.

        Args:
            base_url: The base URL for HTTP requests
        """
        pass

    def get(self, path: str) -> dict:
        """
        Make a GET request and track caching behavior.

        Args:
            path: The URL path to request

        Returns:
            Response data as a dictionary
        """
        pass

    def get_stats(self) -> dict:
        """
        Get cache statistics.

        Returns:
            Dictionary with keys:
            - total_requests: Total number of requests made
            - cache_hits: Number of responses served from cache
            - cache_misses: Number of requests that went to origin
            - revalidations: Number of stale responses revalidated
            - stored_responses: Number of responses stored in cache
        """
        pass

    def reset_stats(self):
        """
        Reset all statistics to zero.
        """
        pass

Dependencies { .dependencies }

hishel { .dependency }

Provides HTTP caching support with state machine implementation.