How do you create a cache that expires in php (or even better, one that refreshes if anything in the page's content has been updated)

Viewed 35

I am trying to set an intelligent cache using PHP. I have used:

$seconds_to_cache = 300; //5 minutes
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");

I have tried it before and after session_start(). The timer only works the first time I load the page. After that it simply refreshes all the content each time without waiting 5 minutes.

How do I make this work?

0 Answers
Related