Skip to content

Image serve: public images sent with Cache-Control: private #2939

Description

@cqnykamp

Problem

handleServeImage in apps/api/src/media/serve.ts sets Cache-Control: private, max-age=300 for every response, regardless of the row's visibility. Two consequences:

  • Public images cannot be CDN-cached. Every fetch hits the API → S3 chain even when the image is open to the world.
  • Visibility transitions leave stale state in browser caches. If an image flips from public to private (or to deleted), browsers can still serve the cached bytes for up to 5 minutes; if it flips from private to public, public viewers get cached 404s for up to 5 minutes.

Suggested fix

Have findViewableImage also return visibility, then branch in handleServeImage:

  • publicCache-Control: public, max-age=<N>
  • unlistedCache-Control: private, max-age=<N> (link-keepers shouldn't be cached by shared intermediaries)
  • private / sharedCache-Control: private, max-age=<N>

Open question: pick N. The current 5 minutes is fine for private; public might want longer (an hour?) but it interacts with how aggressive we want the "go private" propagation to be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    Status
    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions