= time() ) { # cache gültig
$ResultArray = file($CacheFile); # lese ins array $ResultArray den inhalt des $CacheFiles ein -> hoffentlich mit \n am ende jedes elementes
# debug: print_r(file($CacheFile));
if ( count($ResultArray) >= 1 ){ # wenn mindestens 1 result gefunden wurde
# echo "
debug: CACHE HIT $CacheFile
";
$_SESSION['ISTHISACACHE'] = 1;
return $ResultArray;
} else { # der cache enthält keine gültigen anzahl an ergebnissen
@unlink($CacheFile); # fehlermeldungen unterdrücken
$_SESSION['ISTHISACACHE'] = 0;
return -1;
}; # if ( count($ResultArray) >= 1 ){
} else { # cache abgelaufen -> ABER X/Y -> lösche datei
$IsAllowedToUseOldCache = IsCurrentLoadHigher( OLDCACHEISALLOWEDTOUSEATTHISLOAD );
if ( $IsAllowedToUseOldCache == 1) {
$ResultArray = file($CacheFile);
$_SESSION['ISTHISACACHE'] = 1;
return $ResultArray;
} else {
@unlink($CacheFile); # fehlermeldungen unterdrücken
$_SESSION['ISTHISACACHE'] = 0;
return -1;
}; # if ( $IsAllowedToUseOldCache == 1) {
}; # if ( $CacheValidTime >= time() ) {
}; # if (file_exists($CacheFile)) {
# never reached
$_SESSION['ISTHISACACHE'] = 0;
return -1;
####################
###### Read Cache Ende
####################
}; # function ReadCache( $CacheType, $SqlQuery ){
function WriteCache( $ResultArray ){
####################
###### Write Cache
####################
if ( ( is_array($ResultArray) ) && ( count($ResultArray) >= 1 ) ){
$CacheFile = $_SESSION['CACHEFILENAME'];
$fh = fopen($CacheFile, 'wb');
flock($fh, LOCK_EX);
# für jeden Eintrag des arrays, schreibe diesen Eintrag in die cache datei
foreach ($ResultArray as $string) {
$string = trim($string); # \n entfernen
fwrite($fh,"$string\n" );
}; # foreach ($ResultArray as $string) {
fclose($fh);
}; # if ( is_array($ResultArray) ){
return 1;
####################
###### Write Cache Ende
####################
}; # function WriteCache( $ResultArray ){
return 1;
/*
# öffne cache datei und lese sie ein!
$fh = fopen($CacheFile, 'r') or warn("Error!!");
flock($fh, LOCK_EX);
while (!feof($fh)) {
$ResultString .= fread($fh, 2048);
}; # while (!feof($fh)) {
fclose($fh);
# teile die ergebnisse jetzt anhand \n auf und speichere sie in einem neuen Array mit \n
foreach ( explode("\n", $ResultString) as $string) {
array_push($ResultArray, "$string\n");
}; # foreach ( explode("\n", $ResultString) as $string) {
return $ResultArray;
*/
?>