Setting HTTP Cache Headers at server-side (PHP+Apache)

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!

Published by Mageek

Just another geek in the world

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: