Skip to content

Cache 404s, bust when documents become public [staging] - #505

Merged
eyeseast merged 3 commits into
stagingfrom
cache-404s
Oct 16, 2026
Merged

eyeseast merged 3 commits into
stagingfrom
cache-404s

Conversation

@eyeseast

Copy link
Copy Markdown
Contributor
  • Purge the CDN cache when a document becomes anonymously visible
  • Cache anonymous document 404s at the CDN

We now cache document URLs in the API for five minutes (configurable with CACHE_CONTROL_NOT_FOUND_MAX_AGE). This covers the frontend, too, since we pass through cache headers now.

We generate a cache tag in the view, so 404s cache but get busted when we purge a document's tag.

This handles a couple cases:

  • Someone embeds a private document, which would have bypassed cache before
  • A bot hits a bad URL
  • A deleted document is still getting traffic

When a private document becomes public, we now purge the cache at the end of that process, so we don't get a stale cache.

duckduckgrayduck and others added 3 commits October 8, 2026 13:03
Exclude the scratch field from AddOnEvents from event lists and expanded run events, which was causing memory issues
Prepares for caching anonymous 404s: every path that makes a document
visible to anonymous users now purges its `doc-{id}` tag.

- update_access: purge on the final chunk, when access actually changes
  (also covers scheduled publishing)
- processing completion, set_page_text and modifications post_process:
  purge when the document is public, not only when cache_dirty is set
- admin: purge on every save, since admin can change access directly

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Anonymous GETs of a document that isn't visible (private, processing,
deleted or missing) now return a 404 the CDN can hold briefly, tagged
`doc-{id}` so the purges from the previous commit clear it.

- DocumentViewSet retrieve and NoteViewSet list send
  `public, max-age=0, s-maxage=CACHE_CONTROL_NOT_FOUND_MAX_AGE`
- new setting CACHE_CONTROL_NOT_FOUND_MAX_AGE (default 300, 0 disables)
- authenticated 404s and malformed ids keep their current headers

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@duckduckgrayduck

Copy link
Copy Markdown
Contributor

Is this on staging? I'd like to test

@eyeseast
eyeseast changed the base branch from master to staging October 16, 2026 20:54
@eyeseast
eyeseast merged commit 1d3e13b into staging Oct 16, 2026
3 checks passed
@eyeseast eyeseast changed the title Cache 404s, bust when documents become public Cache 404s, bust when documents become public [staging] Oct 16, 2026
@eyeseast

Copy link
Copy Markdown
Contributor Author

Now it's on staging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants