HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Server Operation (http://www.howtoforge.com/forums/forumdisplay.php?f=5)
-   -   Cache Control (http://www.howtoforge.com/forums/showthread.php?t=50722)

entertheraptor 29th December 2010 04:39

(SOLVED) Cache Control
 
Here's the deal, I make modifications to pages on my server and then go to my site and the mods aren't visible. So I refresh the page and there they are.

I'm figuring this is because my browser is caching the pages and recalling them from the cache rather than loading them fresh from the server.

This is no good to me as the content on my pages will be changing frequently so I need browsers to not cache my pages.

I tried the META CACHE-CONTROL tag but it didn't work in any of three browsers (IE, Firefox and Chrome) and a little reading tells me that the best way to deal with this issue is server side.

I'm running Ubuntu 10.10 installed as per the "Perfect Server - Ubuntu 10.10 [ISPConfig 3]" guide. How do I activate and configure mod_cache and mod_expires? (or should I?)

Advice on how to best handle this please. (with detailed instructions for dummies would be nice)

falko 29th December 2010 15:51

You can use PHP to set headers that disable caching, e.g. like this:
PHP Code:

<?php
header
("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>


entertheraptor 30th December 2010 02:07

Wow, all the reading I did and NO ONE anywhere talked about or suggested this method. It's all about META tags that don't work or controlling cache with server configuration.

This is so simple and perfect, thanks falko you're a legend. How would you like to have a crack at my thread about getting a error 500 when I try to access Roundcube using mydomain.com/mailbox :)

Just quickly, I assume that this code goes in the <HEAD> section of your php page. Is this correct?

Oh, and where the above code sets the expiration date, can I use -1 rather than a date?

falko 30th December 2010 17:43

Quote:

Originally Posted by entertheraptor (Post 247750)
Just quickly, I assume that this code goes in the <HEAD> section of your php page. Is this correct?

This goes before anything else - there must not be any output (not even the <head> section or the document type definition) before these lines.

Quote:

Originally Posted by entertheraptor (Post 247750)
Oh, and where the above code sets the expiration date, can I use -1 rather than a date?

Haven't tried that, but you can simply use the date I posted because it's in the past.

entertheraptor 30th December 2010 21:28

Yep, got it now. Great work falko, thanks heaps :)


All times are GMT +2. The time now is 01:07.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.