exists(cache::genCacheName())) { $cachetime = self::expiry($page); $timestamp = time() - $cachehandler->age($cachefile); if (config::get('cache_update') == '*' && file_exists(KB_CACHEDIR.'/killadded.mk') && $timestamp < @filemtime(KB_CACHEDIR.'/killadded.mk')) { $timestamp = 0; } else { $cacheupdate = explode(',', config::get('cache_update')); if (($page != '' && in_array($page, $cacheupdate)) && file_exists(KB_CACHEDIR.'/killadded.mk') && $timestamp < @filemtime(KB_CACHEDIR.'/killadded.mk')) { $timestamp = 0; } } if (time() - $cachetime < $timestamp) { // Alternatively, use a hash of the file. More cpu for a little // less bandwidth. Possibly more useful if we keep an index. // filename, age, hash. Age would be used for cache clearing. $etag = md5($cachefile.$timestamp); if ($usegz && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip") !== false) $etag .= 'gz'; header("Etag: \"".$etag."\""); header("Last-Modified: ".gmdate("D, d M Y H:i:s", $timestamp)." GMT"); // There was a reason for having both checks. etag not always // checked maybe? if ((isset($_SERVER['HTTP_IF_NONE_MATCH']) && strpos($_SERVER['HTTP_IF_NONE_MATCH'], $etag) !== false) || (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $timestamp)) { header($_SERVER["SERVER_PROTOCOL"]." 304 Not Modified"); exit; } if ($usegz) { ob_start("ob_gzhandler"); } else { ob_start(); } echo $cachehandler->get($cachefile); ob_end_flush(); exit(); } if ($usegz) { ob_start("ob_gzhandler"); } else { ob_start(); } } // Don't turn on gzip when sending images. elseif (cache::shouldCache($page)) { if ($usegz) { ob_start("ob_gzhandler"); } else { ob_start(); } } // If the page cache is off we still compress pages if asked. else if ($usegz) { ob_start("ob_gzhandler"); } } /** * Generate the cache for the current page. */ public static function generate($page = null) { if (!is_string($page)) { $page = null; } if (cache::shouldCache()) { $usegz = config::get('cfg_compress') && !ini_get('zlib.output_compression'); $cachefile = cache::genCacheName(); if (defined('DB_USE_MEMCACHE') && DB_USE_MEMCACHE == true) { $cachehandler = new CacheHandlerHashedMem(); } elseif (defined('DB_USE_REDIS') && DB_USE_REDIS == true) { $cachehandler = new CacheHandlerHashedRedis(); } else { $cachehandler = new CacheHandlerHashed(); } $cachehandler->put($cachefile, preg_replace('/profile -->.*Cached ' .gmdate("d M Y H:i:s").'