No revalidation when using stale-while-revalidate

Adam Volek adam.volek at cdn77.com
Thu Jul 23 18:06:36 UTC 2020


Hi,

We're running into some strange behaviour with the 
stale-while-revalidate extension of the cache-control header when using 
nginx as a reverse proxy. When there is a stale response in the cache 
with nonzero stale-while-revalidate time, nginx attempts revalidation 
but seems to ignore the upstream answer if it has specific status code, 
such as 404 or 500, and server a stale response to the client. Other 
response codes such as 200 or 410 don't trigger this behaviour. Is this 
intended, and if so, is there a way to configure nginx to treat 404 as 
any other response?

I understand that this behaviour might be desirable in some situations 
(especially for the responses with 5xx status codes), but in our case, 
if the upstream return a 404 response, we would want the cache to start 
returning it as well as soon as the revalidation is finished.

Below is a minimum nginx.conf we used to replicate the issue.

Kind regards,
Adam Volek


events {}

http {
     proxy_cache_path /tmp/ngx_cache keys_zone=one:10m;
     proxy_cache one;

     server {
         listen 8080 default_server;

         location / {
             proxy_pass http://example.com/;
         }
     }
}


More information about the nginx mailing list