CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-hishel

Persistent cache implementation for httpx and httpcore following RFC 9111 specification

74

1.48x
Overview
Eval results
Files

task.mdevals/scenario-4/

Cache Entry Cleanup System

Overview

Build a cache cleanup system that implements soft deletion with a configurable grace period. The system should mark entries as deleted without immediately removing them, allowing for a grace period before permanent deletion. Additionally, implement batch cleanup to efficiently process multiple entries.

Requirements

1. Soft Deletion with Grace Period

Implement a deletion mechanism that:

  • Marks cache entries as deleted using a timestamp (e.g., deleted_at) rather than immediately removing them
  • Preserves the entry in storage during the grace period (e.g., 1 hour)
  • Allows the entry to remain queryable/recoverable during the grace period
  • Permanently removes entries only after the grace period expires

2. Batch Cleanup Process

Implement an automatic cleanup process that:

  • Identifies entries eligible for permanent deletion (soft-deleted entries past the grace period)
  • Processes entries in configurable batches (e.g., 200 entries at a time) for memory efficiency
  • Removes expired TTL-based entries alongside soft-deleted entries
  • Handles large numbers of entries without memory issues

Implementation Details

Use persistent storage for the cache. Configure grace periods, batch sizes, and TTL values as needed for testing. Ensure the cleanup process can handle both soft-deleted entries and TTL-expired entries efficiently.

Dependencies { .dependencies }

hishel { .dependency }

Provides HTTP caching with persistent storage backends.

Test Cases

test_cache_cleanup.py { .spec-file @test }

Test the cache cleanup functionality:

import asyncio
import time

async def test_soft_deletion_grace_period():
    """Test that soft-deleted entries are preserved during grace period."""
    # Create cache storage
    # Add a cache entry
    # Soft delete the entry
    # Verify entry still exists in storage with deletion timestamp
    # Simulate grace period passing
    # Run cleanup
    # Verify entry is permanently removed
    pass

async def test_batch_cleanup_efficiency():
    """Test that cleanup processes many entries in batches."""
    # Create storage with 500 entries
    # Set 300 entries to be expired/deleted
    # Configure batch size of 200
    # Run cleanup
    # Verify all 300 entries are removed despite batch processing
    pass

Expected behavior:

  • Soft-deleted entries have a deleted_at timestamp and remain in storage during the grace period
  • After the grace period expires, cleanup permanently removes the entries
  • Batch processing efficiently handles hundreds of entries without loading all into memory

Install with Tessl CLI

npx tessl i tessl/pypi-hishel

tile.json