it would be nice to serve appropriate cache headers in the REST interface so that you can just slap nginx/cloudflare in front of it and have a nice caching proxy. Eg getXbyheight requests would get cached for 5 seconds and getYbyhash requests could get cached for a month/year.
-
TheBlueMatt commented at 9:46 PM on November 6, 2025: contributor
-
TheBlueMatt commented at 9:47 PM on November 6, 2025: contributor
@achow101 said she'd work on this
- DrahtBot added the label RPC/REST/ZMQ on Nov 7, 2025
-
waketraindev commented at 9:31 AM on November 9, 2025: contributor
Cache-Control headers can be easily handled at the nginx layer. Rather than adding this logic directly in Bitcoin REST code, it might make sense to include a sample nginx config under contrib/ with reasonable defaults for REST endpoints.
# Example include: rest-cache.conf location /rest/block/ { # Cache block lookups by hash for a long time (immutable) if ($uri ~ "^/rest/block/[0-9a-f]+\.json$") { add_header Cache-Control "public, max-age=31536000, immutable"; } # Cache height-based lookups briefly (chain tip changes) if ($uri ~ "^/rest/block/[0-9]+\.json$") { add_header Cache-Control "public, max-age=5"; } }This could be included in nginx
serverorlocationblocks to provide sensible defaults without changing the rest implementation itself.End users could then fine tune it as needed, for example adding rate limiting, conditional caching or more advanced cache key logic depending on their deployment setup.
-
w0xlt commented at 12:10 AM on March 11, 2026: contributor
Proposed solution: https://github.com/bitcoin/bitcoin/pull/34794
Contributors
Labels