I have a specific need where I am caching 404 responses and not 200 for a request. So, when a request is sent, say for example.com/page_A and if the page is not yet setup in origin, then this 404 is cached for a minute as follows
proxy_cache_valid 404 1m;
proxy_cache_valid any 0;
But when this page is actually setup in origin and it starts sending 200, NGINX still continues to send STALE 404 as it has already cached 404 response for this request.
Currently recycling NGINX instances fixes this issue for us. But I am trying to find a solution to PURGE request specific cache in such cases without recycling NGINX instances.
I have already looked at proxy_cache_purge
directive. But it's available only with commercial subscription.
FYI, cache definition
proxy_cache_path /nginx/cache keys_zone=main_cache:48m levels=1:2 inactive=24h max_size=10g use_temp_path=off;