PHP offers an extremely simple solution for dynamic caching in the form of output buffering. The front page of the site (which currently generates the largest traffic) is now served from a cached copy if it has been cached in the last 5 minutes.
<?php $cachefile = "cache/".$reqfilename.".html"; $cachetime = 5 * 60; // 5 minutes // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) { include($cachefile); echo "<!-- Cached ".date('jS FYH:i', filemtime($cachefile))." -->n"; exit; } ob_start(); // start the output buffer ?> .. Your usual PHP and HTML here ... <?php // open the cache file for writing $fp = fopen($cachefile, 'w'); // save the contents of output buffer to the file fwrite($fp, ob_get_contents()); // close the file fclose($fp); // Send the output to the browser ob_end_flush(); ?>
This is a simple cache type,
you can see it here
http://www.theukwebdesigncompany.com/articles/php-caching.php
You can use smarty to cache
http://www.nusphere.com/php/templates_smarty_caching.htm
sathish
source share