Cache and deliver your content with lightning speed, and save your server the overhead of repeating itself over and over. This class takes care of all of the file management and header controls for you. Some excellent resources that I used on the subject are at:

You should call this method just as soon as you know what page you want to load, and before you open your database. This is not a piecemeal caching machine that saves a database call or two, this class is designed to get your content to your visitor as soon and fast as possible. If you are delivering custom content, or tell Bill hi on every page to make it personal, then this class will not work for you (unless all of your visitors happen to be named Bill).

$url The relative url you would like this page to be cached as. eg. 'folder/page.html' The only pages that can be cached with this class are 'html', 'xml', 'rss', 'atom', 'css', 'js', and 'txt' files.
$expire How often you would like this page to be re-cached in the form of " ". eg. ('4 seconds', '8 minutes', '15 hours', '16 days', '23 months', or '42 years', etc.) It can also be a timestamp of the last mod date. This will make sure that the cached page is current. If you leave it empty, you can always delete the cache later and everything will be updated then.
Returns True or false, but it's pretty predictable. If you include a $url, and it's of the correct type then it will return true. If this method returns false then a cached version will neither be created nor delivered.
Example
$code = md5($_SERVER['REQUEST_URI']); // a great way to include any url parameters 
$cache = new Cache ("folder/.html", '15 min');

If you only want your page to be accessible via one url (a good idea), then this method is here to save the day. This method may seem a little late in the game as the constructor should have already delivered the page and cancelled the script, but that is only if the cached page exists. If your url can be accessed from 'page.php?id=1', or 'seo-seeded-url.html' (preferred), then redirect the user to the preferred url using this method, and then cache the page.

$url The relative url you would like to enforce. The default is whatever you are naming the cached page.
Example
$cache->enforce ('seo-seeded-url.html');

This method caches the $html to the $url specified in the constructor, delivers the content, and ends the script. If the class constructor returned false then this method will do nothing for you.

$html Add everything in the page to your $html var, and put it here.
Example
$html = $page->display ($html);  
$cache->page($html);  
echo $html; // just in case this page is not being cached  
ob_end_flush();

This method will clear your entire cache so that you can start afresh. This class also offers a protected 'remove' method that can be more specific for more advanced applications, but this clear method will get you by just fine.

Example
$cache->clear();
Download