Return to Snippet

Revision: 12170
at March 4, 2009 14:51 by iTony


Initial Code
if (isset($useCache) && $useCache==1){ 
    if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']!="/"){  
        $cacheName=str_replace('/','-',$_SERVER['REQUEST_URI']); 
        $cacheName = substr($cacheName,1);
    }else{
        $cacheName='site-index.html';
    }

    $cacheFile = "cache/{$cacheName}";

    if(!isset($cacheTime)){ 
        $cacheTime = 4 * 60;
    }

    if (file_exists($cacheFile) && time() - $cacheTime < filemtime($cacheFile)) {
        include($cacheFile);
        exit;
    }

    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($cacheFile, 'w');
    fwrite($cached, ob_get_contents());
    fclose($cached);
    ob_end_flush(); // Send the output to the browser
}

Initial URL
http://paste.org/5666

Initial Description

                                

Initial Title
Cache Page Script

Initial Tags
php, cache

Initial Language
PHP