You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 server or location blocks 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.
Activity
TheBlueMatt commentedon Nov 6, 2025
@achow101 said she'd work on this
waketraindev commentedon Nov 9, 2025
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.
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.
achow101 commentedon Dec 23, 2025
I don't remember saying this, and I have no intention of working on this in the foreseeable future.
w0xlt commentedon Mar 11, 2026
Proposed solution: #34794
Merge bitcoin#34794: rest: add Cache-Control headers to REST responses