0

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;
Jinks
  • 3
  • 2

1 Answers1

-1

You can configure nginx.conf and add: add_header X-Cache-Status $upstream_cache_status;

This example adds the X-Cache-Status HTTP header when responding to the client. The following are the possible values for $upstream_cache_status:

  • Miss - The response was not found in the cache, so it was obtained from the original server. The response can then be cached.
  • BYPASS - The response is fetched from the original server, not from the cache, because the request matches the proxy_cache_bypass directive. (See "Can I punch holes through my cache?" below) The response can then be cached.
  • EXPIRED - The entry in the cache has expired. The response contains new content from the origin server.
  • STALE - The content is stale because the original server did not respond correctly and proxy_cache_use_stale is configured.
  • UPDATED - The content is stale because the entry is currently being updated in response to a previous request and the proxy_cache_use_stale update is configured.
  • REVALIDATED - The proxy_cache_revalidate directive is enabled and NGINX verifies that the currently cached content is still valid (If-Modified-Since or If-None-Match).
  • HIT - The response contains valid fresh content directly from the cache.
john_0xFF
  • 9
  • 1