Ok got it working and tested it with a example 1, 2 and 3 all those worked just fine.
This will allow multiple caches to be rolled into one cache file, rather than cache a seperate header, body and footer it will cache all three into one cache file.
You may have to test it with all your examples
NOTE: this with with my mode where I removed the trailing slash
Added these three vars
VAR $CACHE_MULTI = FALSE;//$CACHE_MULTI number of files to cache. if you have defined header.html, body.html and footer.html then this will be set to 3
VAR $CACHE_MULTI_CNT = 0; Used to count iterations
VAR $CACHE_COMPLETE = FALSE; // set to true when all files have been cached.
FUNCTION cache_file( $content = "" )
{
$RW = 'w';
$Temp = $this->cache_file_is_updated();
//$this->error("USE_CACHE = ( $this->USE_CACHE )<BR>cache_file_is_updated: ( $Temp )",0);
IF ( ($this->USE_CACHE) OR (!$this->cache_file_is_updated())) {
IF ( !$this->CACHING) {
//$this->error("Cache file self_script_in_cache_path)",0);
$fname = $this->self_script_in_cache_path();
}ELSE{
//$this->error("Cache file CACHING",0);
$fname = $this->CACHING;
}
$fname = $fname.".ft";
// Tendo certeza que o arquivo existe e que há permissão de escrita primeiro.
//IF ( is_writable($fname)) {
// Opening $fname in writing only mode
IF( $this->CACHE_MULTI > 1 ) {
IF ( $this->CACHE_MULTI_CNT == 0 ){ //new cache
$RW = 'w';
}ELSE{
$RW = 'a';
}
$this->CACHE_MULTI_CNT++;
//$this->error("Cache file Count: ( $this->CACHE_MULTI_CNT )<BR>RW: ( $RW )",0);
IF ( $this->CACHE_MULTI_CNT === $this->CACHE_MULTI ){
$this->CACHE_MULTI_CNT = 0;
$this->CACHE_COMPLETE = TRUE;
}
}
IF ( !$fp = fopen($fname, $RW)) {
$this->error("Error WHILE opening cache file ($fname)",0);
RETURN;
}
// Tendo certeza que o arquivo existe e que há permissão de escrita primeiro.
//IF ( is_writable($fname)) {
// Opening $fname in writing only mode
IF ( !fwrite($fp, $content) ) {
$this->error("Error WHILE writing cache file ($fname)",0);
RETURN;
}ELSE{
fclose($fp);
IF ( $this->CACHE_COMPLETE OR $this->CACHE_MULTI <= 1 ){ #use include cache upon completed or single page cache
include $fname;
}
RETURN;
}
//$this->error("Error WHILE writing cache file ($fname) <br>Count = ($CACHE_MULTI_CNT) <br>cachmulti=($CACHE_MULTI)",0);
fclose($fp);
//} ELSE {
// $this->error("The cache file $fname is not writable",0);
// RETURN;
//}
}
//------------------------------------------------ -------------------------
/*
IF ( ($this->USE_CACHE) && (!$this->cache_file_is_updated())) {
IF ( !$this->CACHING) {
$fname = $this->self_script_in_cache_path();
}ELSE{
$fname = $this->CACHING;
}
$fname = $fname.$this->CACHE_EXT;
// Tendo certeza que o arquivo existe e que há permissão de escrita primeiro.
//IF ( is_writable($fname)) {
// Opening $fname in writing only mode
IF ( !$fp = fopen($fname, 'w')) {
$this->error("Error WHILE opening cache file ($fname)",0);
RETURN;
}
// Writing $content to open file.
IF ( !fwrite($fp, $content)) {
$this->error("Error WHILE writing cache file ($fname)",0);
RETURN;
}ELSE{
fclose($fp);
include $fname;
RETURN;
}
fclose($fp);
//} ELSE {
// $this->error("The cache file $fname is not writable",0);
// RETURN;
//}
}
*/
//------------------------------------------------ ------------------------
} // end cache_file() |