Fix fastcgi cache serving stale content for unpublished pages - #1642
Conversation
Remove `updating` from `fastcgi_cache_use_stale` by default so nginx waits for the fresh upstream response instead of serving stale cached content. This prevents unpublished/drafted pages from continuing to be served from cache indefinitely. Add `nginx_cache_use_stale_updating` variable (default: false) so users who prefer stale-while-revalidate behavior can opt back in. This is a behavior change: previously nginx served stale cache entries while background updates fetched fresh content. The new default favors correctness (fresh responses) over latency during cache refreshes. Closes #1551 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
CI failure here is expected: this is an The test is still marked Cleanup is tracked in #1648, which removes the |
Local verificationBranch tested: SetupTemporary config: Config diffBefore (master): After ( Test 1:
|
| Scenario | After unpublish |
|---|---|
master (updating hardcoded) |
200 STALE indefinitely |
fix, default (updating off) |
200 HIT → 404 Not Found |
fix, opt-in (updating on) |
200 HIT → 200 STALE (expected) |
Conclusion: Verified locally — updating removed from fastcgi_cache_use_stale by default. Unpublished pages stop serving stale 200 once cache expires. Opt-in via nginx_cache_use_stale_updating: true preserves previous behavior.
Replace the boolean `nginx_cache_use_stale_updating` toggle with a `nginx_cache_use_stale` variable containing the full directive value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Align test with #1642 which replaced the boolean nginx_cache_use_stale_updating with a full-value nginx_cache_use_stale variable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
fastcgi_cache_use_stalefully configurable via thenginx_cache_use_stalevariableerror timeout invalid_header http_500(withoutupdating), so nginx waits for the fresh upstream response instead of serving stale cached content when pages are unpublished/draftedRelated: #1641 addresses cached redirects causing loops (#1594)
Closes #1551
Breaking change
This changes the default caching behavior. Previously, nginx served stale cache entries while background updates fetched fresh content (
fastcgi_cache_use_stale updating). The new default favors correctness (immediate fresh responses) over latency during cache refreshes.To restore the previous behavior:
Test plan
nginx_cache_use_stale: publish a page, visit it, unpublish → should return 404 immediately after cache expires (default 30s)updatingadded back: confirm stale-while-revalidate behavior is preserved🤖 Generated with Claude Code