Skip to content

Cache headers in REST #33809

Closed
Closed

Description

@TheBlueMatt

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.

Activity

  1. TheBlueMatt commented on Nov 6, 2025

    @TheBlueMatt
    ContributorAuthor

    @achow101 said she'd work on this

  2. waketraindev commented on Nov 9, 2025

    @waketraindev
    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 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.

  3. achow101 commented on Dec 23, 2025

    @achow101
    Member

    @achow101 said she'd work on this

    I don't remember saying this, and I have no intention of working on this in the foreseeable future.

  4. w0xlt commented on Mar 11, 2026

    @w0xlt
    Contributor

    Proposed solution: #34794

  5. added a commit that references this issue on Aug 10, 2026
    b6bd573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions