Does stale-while-revalidate work if the URL is purged via the API?

Does stale-while-revalidate work if the URL is purged via the API, or does it only work if the URL expires based on s-maxage value?

For example. If I have a page that is cached by Cloudflare with the following response header.

Cache-Control: max-age=0 s-maxage=14400 stale-while-revalidate=300

If I then purge that page via Cloudflare’s API.

The next request to that URL will make Cloudflare re-fetch from origin. In-between Cloudflare fetching from origin and caching the response, another request is made for that URL. Will Cloudflare serve the stale version? Or does that only happen if the cached response expires “naturally” (ie. after s-maxage=14400)?

Testing this myself, it doesn’t appear to work.

Purging via API I imagine would be the same as deleting a file from a disk, so there isn’t anything stale to serve…

This topic was automatically closed after 30 days. New replies are no longer allowed.