Q:

How to force re-caching of updated webpages

Dear Stack Overflowers,
I feel that my problem must be very common, which makes the fact that I'm failing to find a solution all more puzzling. Perhaps my poor searching skills are to blame.
I'm in charge of maintaining my wife's website, which mainly consists of on-line series. The site uses php to generate pages from a MySQL database (I guess that would make it dynamically generated). Every time a new episode is added I need to update a couple of pages (index and the penultimate episode pages) with links and images to point to this new episode. The obvious problem is that cached versions of the website would not have that updated link. That is unless the visitor reloads one of those updated pages. One way to deal with it would be to make those two pages non-cacheable, but that seems a bit brutal.
I have read several resources on Cache-Control, but am still at loss figuring out which parameters would be useful in this particular situation. Since I don't know, when the next episode will be published, I can't use 'Expires' or 'max-age' (or can I?). Similarly, since I need to re-load the whole page, I can't just change the file name, as I could for an image. What I would ideally like to do is to compare the date of the cached version and the last-modified date of the file and if the cache version is older than the file - force the browser load the new version. But I'm open to other approaches.
I'd be equally happy to either modify htaccess file or add the php Header. Any suggestions would be much appreciated.
Many thanks!

A:

In PHP, just send the right headers:
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.

Headers control how the browser acts with various things, from how long to cache for, to what type of information is being sent (html, image etc).
Dropping the headers there will force an update each time someone request the page.
If the page is really too big to send each time (really? is it really that big?) then why not just set the cache to expire once every day, or once a week - some value where it's not too long so folks don't miss stuff, but also not to common so they don't download too much.
The other completely different approach might actually be to have your code spit out tatic HTML pages that are never cached - some HTML can't be too many kbs of data to send and it saves your server getting too many requests.

