Recently I was trying to debug a WordPress site. I notice from the response headers on the pages, most of them have a “cache-control: max-age=600, public” header. Since I’m constantly changing code on certain pages and would like to see immediate effect, I decided to change the cache-control header to “no-store, must-revalidate”.
In the functions.php, I added this line at the top
header("Cache-Control: no-store, must-revalidate");
Even after that, the response header is still cache-control: max-age=600, public
. I was googling about the issue for like an hour to no avail. Then I suddenly remember one can also set Headers in Apache settings. And voila, there it was. I found this line in the site settings (under the folder /etc/apache2/sites-available/)
Header set cache-control "public, max-age=30"
So this is the culprit. After I changed it to “no-store, must-revalidate” and restarted the apache server by service apache2 restart
, the cache-control header in the response headers are finally correct!