if ($batcache->cache_control && isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$since = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
if ($batcache->cache['time'] == $since) {
header('Last-Modified: ' . $_SERVER['HTTP_IF_MODIFIED_SINCE'], true, 304);
exit;
}
}
// Use the batcache save time for Last-Modified so we can issue "304 Not Modified"
if ($batcache->cache_control) {
header('Last-Modified: ' . date('r', $batcache->cache['time']), true);
header('Cache-Control: max-age=' . ($batcache->max_age - time() + $batcache->cache['time']) . ', must-revalidate', true);
}
// Add some debug info just before </head>
if ($batcache->debug) {
if (false !== ($tag_position = strpos($batcache->cache['output'], '</head>'))) {
$tag = "<!--\n\tgenerated " . (time() - $batcache->cache['time']) . " seconds ago\n\tgenerated in " . $batcache->cache['timer'] . " seconds\n\tserved from batcache in " . $batcache->timer_stop(false, 3) . " seconds\n\texpires in " . ($batcache->max_age - time() + $batcache->cache['time']) . " seconds\n-->\n";
$batcache->cache['output'] = substr($batcache->cache['output'], 0, $tag_position) . $tag . substr($batcache->cache['output'], $tag_position);
}
}
if (!empty($batcache->cache['headers'])) {
foreach ($batcache->cache['headers'] as $k => $v) {
header("{$k}: {$v}", true);
}
}
if (!empty($batcache->headers)) {
foreach ($batcache->headers as $k => $v) {
if (is_array($v)) {
header("{$v[0]}: {$v[1]}", false);
} else {
header("{$k}: {$v}", true);
}