Monitoring cache status
When developing complex sites or rapidly changing content, one key aspect is to monitor where the content was served from. Essentially, we need to know whether we hit the cache or whether it was a miss.
This helps us ensure that, if there are issues, or on seeing incorrect content, we know where to look. It can also be used to ensure the caching is working on pages where it's expected and being bypassed for areas where it shouldn't be.
Getting ready
As the caching is part of the standard NGINX platform, no additional prerequisites are required.
How to do it...
One of the easiest ways is to simply add an additional header. To do this, we add the additional directive to our existing proxy configuration within the location
block directive:
proxy_set_header X-Cache-Status $upstream_cache_status;
How it works...
NGINX internally tracks the status of the request ($upstream_cache_status
), so by exposing it as a header, we can now see it from the client side. If we use Google DevTools...