Persistent cache implementation for httpx and httpcore following RFC 9111 specification
74
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.
Implement a deletion mechanism that:
deleted_at) rather than immediately removing themImplement an automatic cleanup process that:
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.
Provides HTTP caching with persistent storage backends.
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
passExpected behavior:
deleted_at timestamp and remain in storage during the grace periodInstall with Tessl CLI
npx tessl i tessl/pypi-hisheldocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10