Will stale-if-error override manual cache purge?

Hello Everyone!

Trying to understand more in-depth what exactly happens while we manually purge our cache. So while CF tries to expire the cache and then fetch the new content from the origin, what if the origin is having problem responding? Will the stale-if-error cache control directive kick in and keep the supposed-already-purged content? Therefore, is the purged content gone forever, or it’s just marked as staled after the purge?

Our company is on Enterprise plan at the moment and we are finding a way to protect this instability of the origin (sometimes out of our control) when purging the cache…

see https://support.cloudflare.com/hc/en-us/articles/115003206852

stale-while-revalidate=seconds

When present in an HTTP response, the stale-while-revalidate Cache-Control extension indicates that caches may serve the response in which it appears after it becomes stale, up to the indicated number of seconds since the resource expired.

If Always Online is enabled, then the stale-while-revalidate and stale-if-error directive are ignored.

stale-if-error=seconds

The stale-if-error Cache-Control extension indicates that when an error is encountered, a cached stale response may be used to satisfy the request, regardless of other freshness information.

The stale-if-error directive is ignored if Always Online is enabled or if an explicit in-protocol directive (e.g., by a no-store or no-cache cache directive, a must-revalidate cache-response-directive, or an applicable s-maxage or proxy-revalidate cache-response-directive) is passed.

From that, it seems if you able Always Online https://support.cloudflare.com/hc/en-us/articles/200168436 it might be what you want in case of origin issues ?

and control from origin

Alternatives to globally enabling Always Online include:

  • Using Cloudflare Page Rules to enable Always Online, or
  • Allowing your origin web server to determine which content to cache for display if your origin web server is offline:
  1. Disable Always Online,
  2. Set Origin Cache Control for your resources, and
  3. Enable stale-if-error at your origin.

Thanks so much! Sorry for being fuzzy but what if we don’t want to enable Always Online? Because sometimes (for some reason), we’ve experienced always-on might not be on…

Also taking this opportunity to go deeper into the cache purge mechanism.

Got confirmation from support that a state-if-error will not survive over a purge. Everything will be completely gone after.

1 Like

Thanks for the update !