Location: PHPKode > scripts > DCC class > dcc-class/include/class.dcc.inc
<?
/////////////////////////////////////////////////////////////
// Engine class for DCC v0.9
// (c) Gregory A. Rozanoff, 2003
/////////////////////////////////////////////////////////////

class dcc {

 var $tm, $signature, $content;
 var $baseURL, $baseDir, $path;

 function init() {						// initialize system variables, needed 4 u script
	$this->tm = time();					// current time
        $this->signature  = md5($_SERVER['REQUEST_URI']);	// calculate hash signature of file path
	$this->baseURL    = "http://localhost/dcc";
	$this->baseDir    = "c:/localhost/www/dcc";
        $this->cachePath  = $this->baseDir."/cache";
        $this->expireTime = 3600;				// page cache expire time in seconds
        $this->path	  = $this->cachePath."/cache_".$this->signature.".cgi";
 } 

 function module() {						// constructor
	$this->init();						// initialize variables
        $this->flush();						// try to expire if need
 }

 function execute() {						// Execute the main script
	if (!$this->fetch())
               	$this->main();
 }
 
 function done() {						// destructor
	$this->add();						// cache content
	echo $this->content;					// flush content
 }

 function add() {						// merge entry into cache
       	if (!file_exists($this->path) && empty($_POST)) {
               	$fp = fopen($this->path, "w");
                fwrite($fp, $this->content);
                fclose($fp);
       	}
 }

 function fetch() { 						// fetch entryes in cache
       	if ($body = @file($this->path))
		if ($_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache' && $_SERVER['HTTP_PRAGMA'] != 'no-cache' && empty($_POST)) {
	               	$this->content = implode("", $body);
	                return TRUE;
        	}
        return FALSE;
 }

 function flush() { 						// remove expired entryes from cache
	if (file_exists($this->path))
        	if ($this->tm - filemtime($this->path) > $this->expireTime)
	        	unlink($this->path);
 }

}

?>
Return current item: DCC class