Adding $upstream_cache_status in HTTP Response Headers

In our checklist for perfect WordPress-Nginx setup, we have a section dedicated to check if page-caching will work in case PHP/MySQL backend crash. Some readers did not like my way of actually shutting down PHP backend for cache-verification.

If you are using Nginx’sfastcgi_cache, then you can useupstream_cache_status variable to test cache for particular URLs without shutting down PHP.

All you need to do is, add a line like below to /etc/nginx/nginx.conf file, in http{..} block:

add_header rt-Fastcgi-Cache $upstream_cache_status;

Just reload nginx config: service nginx reload

Check HTTP response for any page and you will see something like:

HTTP/1.1 200 OK
Server: nginx
Date: Fri, 26 Jul 2013 15:38:51 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.4.17-1~precise+1
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-Pingback: https://rtcamp.com/xmlrpc.php
rt-Fastcgi-Cache: HIT

Please note last line. Value next to rt-Fastcgi-Cache indicates fastcgi-cache status.

If you see a MISS, send similar request again and it should get you a HIT.

If you see BYPASS, that means some conditions for skipping cache are met.

Related: Using $upstream_cache_status improving cache efficiency

Discuss your project
with our experts

No obligation. Limited slots.

Contact Form Business Enquiry

"*" indicates required fields

Please attach any RFP, project specification, or document that you would like to share.
Drop files here or
Max. file size: 5 GB.
    This field is for validation purposes and should be left unchanged.