I\'ve read several guides on implementing a php cache system (my site is custom coded, fairly query heavy and growing) including this one: http://www.snipe.net/2009/03/quick
Here's my tip: create either an object or function that lets you cache a "section" based upon its name. This way you can cache part of your page, and include the rendering section within an if block. What I did was hash the incoming text and used that as the filename within './cache', and returned the boolean value of whether or not regeneration is needed; you will obviously need output buffering for this.
This would give you a cache framework of,
if(Cache::cached('index-recent-articles', 5 /* minutes */)) {
Cache::start();
echo 'stuff here';
Cache::stop('index-recent-articles');
} // And if Cache::cached could echo the cached HTML when the result is false...
// then this is a tidy else-less bit of code.
I don't know if this is optimal, a server-based solution like memcache would be better, but the concept should help you. Obviously how you manage the cache, whether by files or by database or extension, is up to you.
Edit:
If you wish for file-based caching then a system this simple may be all you need. Obviously I haven't tested it in your shoes, and this is mostly just pulled from the back of my head, but as it stands this is a decent start for what you may desire.
abstract class Cache {
const path = 'cache/';
static function start() { ob_start(); }
static function end($id, $text = null) {
$filename = sprintf('%s%u', Cache::path, crc32($id));
file_put_contents($filename, $text === null ? ob_get_clean() : $text);
}
static function cached($id, $minutes = 5) {
$filename = sprintf('%s%u', Cache::path, crc32($id));
$time = $minutes * 60;
if(time() - filemtime($filename) > $time) {
return true;
} else {
echo file_get_contents($filename);
return false;
}
}
}