02-12-2009, 03:25 PM
|
#36 (permalink)
|
|
The Wanderer
Join Date: Feb 2009
Posts: 11
Thanks: 2
|
Instead of using some database, which sounded so complicated and making more connections etc.
I went for a file based caching with the use of ob_start() and ob_end_flush().
PHP Code:
<?php if ($_GET['name']) { $cachefile = 'cache/'.$_GET['name'].'.cache'; // different cache file for each member profile } else { $cachefile = 'cache/roster.cache'; // main members page cache file. } $cachetime = 24 * 60 * 60; // hold the cache for 1 day before re-fetching data from armory. if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) { include($cachefile); // if cache is not older than 1 day include the cache file. echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." -->\n"; exit; // stop continuing the script if cache file is included. } ob_start(); // start buffering/caching up. require_once("header.php"); ?> Your usual HTML and or PHP code here, in other words your dynamic content such as this armory member stuff. <?php require_once("footer.php");
$cachefp = fopen($cachefile, 'w'); fwrite($cachefp, ob_get_contents()); //write the buffered/cached data to the cache file. fclose($cachefp); ob_end_flush(); ?>
Simple but seems to be working :)
|
|
|
|