Open
Conversation
…request modes Serve expired entries within their stale-while-revalidate window in the generic middleware path not only when the request sends max-stale. This updates stale validation to honor response-side stale-while-revalidate in strict mode, and moves generic background revalidation onto a detached request context so async refresh can complete after the client request ends. Also adds regression coverage for stale-while-revalidate behavior in strict and bypass_request modes, plus an RFC-level test for SWR stale age validation.
✅ Deploy Preview for teal-sprinkles-4c7f14 canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A soft purge marks cached entries stale instead of deleting them immediately, so the stale response can still be served while a background refresh or revalidation updates the object. This is similar to Nginx
fastcgi_cache_use_stale: updating.Created this while researching alternatives to Fastly's surrogate keys with soft purge, as it is super useful for large publishers that frequently publish content and want to ensure that end-user never experience slow response time (arriving on cold, invalidated responses).
Changes
Souin-Purge-Mode: softheaderCache-Status ... fwd=stale/flushbypass_requestbehavior unchanged for normal request handlingflushwhen clearing surrogate indexesCaddy / middleware fixes included
This also fixes the background revalidation path used by Caddy so the refresh does not reuse a canceled request context.
It also restores generic
stale-while-revalidatebehavior instrictandbypass_requestmodes.Tests
Added coverage for:
304 Not Modifiedbypass_requestbehavior with soft purgestale-while-revalidateinstrictmodestale-while-revalidateinbypass_requestmodeServerheaderRelated
stale-while-revalidatenot triggering background revalidation in eitherbypass_requestorstrictmode #684Disclaimer: GPT-5.4 was used to create the majority of this change.