/** * The output buffer callback used to capture the output and cache it. * * @see StaticCache::init() * @param string $buffer The output buffer contents * @return string $buffer unchanged */ public static function store_final_output($buffer) { // prevent caching of 404 responses if (!URL::get_matched_rule() || URL::get_matched_rule()->name == 'display_404') { return $buffer; } $request_id = StaticCache::get_request_id(); $query_id = StaticCache::get_query_id(); $expire = Options::get('staticcache__expire', StaticCache::EXPIRE); // get cache if exists if (Cache::has(array(StaticCache::GROUP_NAME, $request_id))) { $cache = Cache::get(array(StaticCache::GROUP_NAME, $request_id)); } else { $cache = array(); } // don't cache cookie headers (ie. session cookies) $headers = headers_list(); foreach ($headers as $i => $head) { if (stripos($head, 'cookie') !== false) { unset($headers[$i]); } } // see if we want compression and store cache $cache[$query_id] = array('headers' => $headers, 'request_uri' => Site::get_url('host') . $_SERVER['REQUEST_URI']); if (Options::get('staticcache__compress') && extension_loaded('zlib')) { $cache[$query_id]['body'] = gzcompress($buffer, StaticCache::GZ_COMPRESSION); $cache[$query_id]['compressed'] = true; } else { $cache[$query_id]['body'] = $buffer; $cache[$query_id]['compressed'] = false; } Cache::set(array(StaticCache::GROUP_NAME, $request_id), $cache, $expire); return $buffer; }