Skip to content

Instantly share code, notes, and snippets.

@deplorableword
Created March 4, 2009 11:15
Show Gist options
  • Save deplorableword/73799 to your computer and use it in GitHub Desktop.
Save deplorableword/73799 to your computer and use it in GitHub Desktop.
<?php
$cacheFile = 'cache/cache.html';
$cacheTime = 4 * 60;
// Serve the cached file if it is older than $cacheTime
if (file_exists($cacheFile) && time() - $cacheTime < filemtime($cacheFile)) {
include($cacheFile);
exit;
}
// Start the output buffer
ob_start();
// put your shit here
// Cache the contents to a file
$cached = fopen($cacheFile, 'w');
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush(); // Send the output to the browser
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment