Stale While Revalidate Expires

Maxim Dounin mdounin at mdounin.ru
Wed Jun 7 14:26:45 UTC 2017


Hello!

On Tue, Jun 06, 2017 at 07:33:24PM +0000, Rafael Cirolini wrote:

> We've just updated to 1.12 to use the stale-while-revalidate option.
> 
> The application is who sends the cache-control header, like this:
> cache-control:max-age=180, stale-while-revalidate=60, stale-if-error=864000
> 
> If I understood how SWR works, the user shouldn't receive stale content after 180+60 seconds.
> 
> But we are seing stale content after this time.
> X-Cache-Status: STALE
> 
> Our DevOps team did a debug:
> 2017/05/22 15:14:31 [debug] 21376#21376: *44 http file cache expired: 4 1495476646 1495476871
> 2017/05/22 15:14:31 [debug] 21376#21376: *44 http upstream cache: 4
> 2017/05/22 15:14:31 [debug] 21376#21376: *44 http file cache send: /var/cache/nginx/d/d2/fb19e1c85db7bda5c92ce21530bf5d2d
> 2017/05/22 15:14:31 [debug] 21376#21376: *44 http ims:1491861925 lm:1491861925
> 2017/05/22 15:14:31 [debug] 21376#21376: *44 http script var: "STALE"
> 
> The correct answer should be EXPIRED after the max-age+SWR time.
> 
> It looks reasonble to you?

The behaviour depends on whether you use "proxy_cache_use_stale 
updating" in your configuration or not:

- If it is explicitly configured, it takes precedence over 
  "Cache-Control: stale-while-revalidate=", and nginx will use any 
  stale response available.

- If not configured, nginx will follow "stale-while-revalidate=" 
  specified in the response.

The debug log provided suggests that the configuration uses 
"proxy_cache_use_stale updating" and 
"proxy_cache_background_update on".

-- 
Maxim Dounin
http://nginx.org/


More information about the nginx mailing list