I have strange problem with nginx microcache. When nginx serve STALE content, it takes too long.
My actual microacha part in config:
...
fastcgi_cache biznisto.sk;
fastcgi_cache_bypass $skip_cache;
fastcgi_cache_key "$scheme$request_method$host$request_uri$rt_session";
fastcgi_cache_valid 200 301 302 5m;
fastcgi_cache_use_stale updating error timeout invalid_header http_500;
fastcgi_cache_lock on;
fastcgi_cache_revalidate on;
fastcgi_cache_background_update on;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
add_header X-Cache $upstream_cache_status;
...
Screens
STALE – wait 565ms
HIT – wait 59ms
Any suggestions?
Thanks
Best Answer
The fastcgi_cache_background_update directive allows updating an expired cache item while the stale cached response is being returned to the client.
If, however, the response is fully returned, but updating is not yet finished, it will delay subsequent actions, including processing of additional requests on the same connection, and/or the closing of the connection.
This behaviour ensures that:
https://trac.nginx.org/nginx/ticket/1329