feat: add persistent on-disk HTTP response cache#61
Open
mkarim1378 wants to merge 1 commit into
Open
Conversation
Adds a two-tier caching system: the existing in-memory ResponseCache
(L1, fast, lost on restart) is now backed by a new on-disk DiskCache
(L2, persistent, survives restarts).
How it works:
- Cache lookup: check memory first; on miss check disk; on disk hit
promote the entry back into memory for future requests.
- Cache write: write to both memory and disk simultaneously.
- Each disk entry is a single binary file: 8-byte expiry timestamp
(little-endian double) followed by the raw HTTP response bytes.
Atomic rename guarantees no partial writes.
- Eviction: expired files removed on every put(); oldest-first
deletion enforces the max_mb size cap.
- Existing TTL and cacheability logic (Cache-Control, no-store,
Set-Cookie, static-asset heuristics) is reused unchanged.
New files:
- src/core/disk_cache.py: DiskCache class (get/put/evict/stats)
Changed files:
- src/proxy/proxy_server.py: initialise DiskCache from config;
L2 lookup and write at both HTTPS-MITM and plain-HTTP paths
- config.example.json: disk_cache section (enabled, max_mb, dir)
- .gitignore: exclude http_cache/ directory
Config (off by default):
"disk_cache": { "enabled": true, "max_mb": 200, "dir": "" }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a two-tier caching system: the existing in-memory ResponseCache (L1, fast, lost on restart) is now backed by a new on-disk DiskCache (L2, persistent, survives restarts).
How it works:
New files:
Changed files:
Config (off by default):
"disk_cache": { "enabled": true, "max_mb": 200, "dir": "" }