Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)

Paste

Pasted as PHP by Tarun ( 17 years ago )
if (isset($useCache) && $useCache==1) // Is caching enabled for this page at init.php ( main controller for my site)
{
if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']!="/")  // Is there any URI to cache
{
$cacheName=str_replace('/','-',$_SERVER['REQUEST_URI']); // Replasing all slashes from URI with "-"
$cacheName = substr($cacheName,1); // Removing first unwanted "-" symbol
}
else
{
   $cacheName='site-index.html'; //If there are no URI, this maybe index.html
}
$cacheFile = "cache/{$cacheName}"; // Cache file name now is clean and we can use it
if(!isset($cacheTime)) // I can set different cacheTime for different parts of my site. For sample I use 1 hour caching time for index page
{
$cacheTime = 4 * 60;
}
// Serve the cached file if it is older than $cacheTime
if (file_exists($cacheFile) && time() - $cacheTime < filemtime($cacheFile)) {
    include($cacheFile);
    exit;
}
// Start the output buffer
ob_start();
}
 
 
/************** Body of site **************/
 
 
if (isset($useCache) && $useCache==1) // Firstly we check, is caching enabled for this page, if yes do your best my script:)
{
$cached = fopen&#40;$cacheFile, 'w'&#41;;
fwrite($cached, ob_get_contents());
fclose($cached);
ob_end_flush(); // Send the output to the browser
}

 

Revise this Paste

Parent: 5666
Your Name: Code Language: