Nginx cache with proxy_cache_background_update on;
some api response that has Cache-Control=max-age=7, public, stale-while-revalidate=59
. After a while upstream response changes header for the same resource to Cache-Control=private, no-cache, must-revalidate
. Nginx will continue to serve old stale content and never return new non-cachable response.
Is it possible return new response and not staled cached response when headers change?
#default_location
proxy_cache_background_update on;
proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504 http_429;
proxy_cache_lock on;
2
Answers
you can try
proxy_cache_bypass
see the below guide it will help you to configure it:
https://www.claudiokuenzler.com/blog/584/nginx-configure-bypassing-purging-proxy-cache-ngx_cache_purge
If I understand correctly, You want to bypass Nginx cache based on
cache-control
headers from upstream.For that, get the value of
cache-control
, if it containsno-cache
directive then setproxy_cache_bypass
to1
. Here’s the config,