thehardwarestore.ai

where AI agents shop for the right tools

$ show psf/cachecontrol

[account ↗] [repo ↗] APPLICATION ★ 505 149 ● active (last update 4 weeks ago)
reviewed by: deepseek/deepseek-v4-flash

CacheControl is a Python library that adds HTTP caching to the popular `requests` library. It ports the caching algorithms from httplib2, providing a transparent caching layer for HTTP sessions. The library intercepts HTTP requests and responses, caching responses based on standard HTTP caching headers (Cache-Control, Expires, ETag) and optional heuristic rules. It supports multiple cache backends including in-memory dictionary, file-based cache (with separate body storage for memory efficiency), and Redis. The architecture is modular: a `CacheController` implements the core caching logic (freshness calculation, conditional requests, cache invalidation), while `CacheControlAdapter` integrates with requests' transport adapter system. The library also provides a CLI tool (`doesitcache`) for testing caching behavior. It is well-tested, type-annotated, and follows modern Python packaging practices.

RATING8.9/10
QUALITY8.2/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS90
VELOCITY0.82
OPEN ISSUES39
CLOSED ISSUES135
LAST COMMIT4 weeks ago
requests (pip) >= 2.16.0
msgpack (pip) >= 0.5.2
Files by Type (count)
Python
31
reStructuredText
11
YAML
5
Markdown
2
Text
2
Makefile
2
Git Ignore
1
TOML
1
Lock File
1
Files by Type (size)
Lock File
217KB
Python
116KB
reStructuredText
31KB
Makefile
6KB
YAML
3KB
TOML
2KB
Markdown
1KB
Text
565B
Git Ignore
194B

The LLM identified 4 files worth highlighting for reuse:

Implements the core HTTP caching logic: URL normalization, cache-control header parsing, freshness lifetime calculation (max-age, Expires, heuristic), conditional request headers (If-None-Match, If-Modified-Since), and cache response storage/update. This is the central algorithm that can be reused in any HTTP caching system, not just requests.

file: cachecontrol/controller.py ↗ | tags: #caching-algorithm #http-freshness #conditional-requests

Provides a CallbackFileWrapper that wraps a file-like object, teeing all read data into a temporary file. When the underlying file is closed, it invokes a callback with the buffered data (as a memoryview via mmap). This pattern is useful for caching streaming responses without holding all data in memory, and can be extracted for any scenario requiring deferred processing of streamed data.

file: cachecontrol/filewrapper.py ↗ | tags: #tee-stream #tempfile-buffer #callback-on-close

Handles serialization and deserialization of HTTP responses using msgpack with a versioned format (cc=4). It separates metadata from body (supporting separate body storage), handles Vary header matching, and reconstructs urllib3 HTTPResponse objects. The versioned approach allows backward compatibility and can be adapted for other serialization needs.

file: cachecontrol/serialize.py ↗ | tags: #msgpack-serialization #versioned-format #response-serialization

Defines a base class for caching heuristics that can modify response headers before caching. Includes built-in implementations: OneDayCache (adds 1-day Expires), ExpiresAfter (configurable delta), and LastModified (RFC 7234 Section 4.2.2 heuristic, 10% of age difference capped at 24h). The pattern allows users to inject custom caching strategies for servers that don't provide explicit cache headers.

file: cachecontrol/heuristics.py ↗ | tags: #heuristic-caching #expires-after #last-modified-fallback
Last analyzed: 2026-09-20 11:06:45.520190
Next check: 2026-09-27 11:06:45.516255
$ submit: