Persistent cache implementation for httpx and httpcore following RFC 9111 specification
74
Build an HTTP cache proxy that intelligently handles stale cached responses according to HTTP caching specifications. The proxy should support configurable staleness policies while respecting cache control directives that prohibit serving stale content.
Your implementation should provide a cache proxy that:
The cache proxy should determine whether to serve stale content based on:
When stale serving is enabled by configuration:
When stale serving is disabled by configuration:
Your implementation must recognize and enforce these directives that prohibit serving stale content:
no-cache: Requires revalidation before servingmust-revalidate: Requires revalidation when staleproxy-revalidate: Requires revalidation when stale (for shared caches)If any of these directives are present in a cached response's Cache-Control header, the cache must not serve the stale response without revalidation, regardless of the stale-serving configuration.
Track whether responses were served from cache by including metadata with each response.
Cache-Control: max-age=10 and the cache expires after 15 seconds @testCache-Control: max-age=10 and the cache expires after 15 seconds @testCache-Control: max-age=10, no-cache and the cache expires after 15 seconds @testCache-Control: max-age=10, must-revalidate and the cache expires after 15 seconds @testCache-Control: max-age=10, proxy-revalidate and the cache expires after 15 seconds @testtest_stale_cache.py containing all test casesProvides HTTP caching capabilities with RFC 9111 compliance, including stale response handling and cache control directive parsing.
Your implementation should demonstrate proper usage of cache configuration and policy mechanisms. The solution should be concise and leverage the caching library's built-in capabilities for staleness checking and directive handling.
@generates
Install 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