Cache negative proxy results to reduce battery drain#12
Open
greenart7c3 wants to merge 1 commit into
Open
Conversation
A request for a blob that is not cached locally triggers a full proxy crawl: a connection attempt to every xs hint server plus a nostr relay lookup per author pubkey, frequently routed through Tor. Nothing about a "not found" outcome was remembered, so a client that keeps asking for an unavailable blob (retries, re-scrolling a feed) re-ran that entire crawl on every request, which is the main battery drain while proxying. Cache the negative result briefly, keyed by the blob hash plus the exact xs/as hints supplied, so repeated identical requests answer 404 without touching the network. A request carrying different hints still gets a fresh crawl, and the short TTL lets a blob that becomes available be picked up soon after. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014cykkDSZo6C4qTruWg3cko
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.
Summary
This PR implements a negative result cache for blob proxy requests to significantly reduce battery consumption when clients repeatedly request unavailable blobs. Previously, each request for a missing blob would trigger a full crawl across all hint servers and relay lookups, even if the blob was already confirmed as unavailable moments earlier.
Key Changes
notFoundCache(ConcurrentHashMap) to store recently failed blob lookups with a 60-second TTL and 256-entry limitproxyCacheKey()to generate cache keys from blob hash, xs servers, and author pubkeys (sorted for consistency)isRecentlyNotFound()to check cache and lazily remove expired entriesmarkNotFound()to record failed lookups with opportunistic cleanup of expired entries when cache reaches capacityImplementation Details
https://claude.ai/code/session_014cykkDSZo6C4qTruWg3cko