Skip to content

Instantly share code, notes, and snippets.

@rduarte
Created June 4, 2009 12:33
Show Gist options
  • Save rduarte/123593 to your computer and use it in GitHub Desktop.
Save rduarte/123593 to your computer and use it in GitHub Desktop.
<?php
$useCache = true;
if ($useCache){
if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']!="/"){
$cacheName=str_replace('/','-',$_SERVER['REQUEST_URI']);
$cacheName = substr($cacheName,1);
}else{
$cacheName='site-index.html';
}
$cacheFile = "cache/{$cacheName}";
if(!isset($cacheTime)){
$cacheTime = 4 * 60;
}
if (file_exists($cacheFile) && time() - $cacheTime < filemtime($cacheFile)) {
include($cacheFile);
exit;
}
ob_start();
}
?>
<!-- Content to be cached -->
<?php
if ($useCache){
file_put_contents($cacheFile, ob_get_contents());
ob_end_flush();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment