--- modules/memcache/memcache.inc 2009-07-02 00:09:45.000000000 -0400 +++ modules/memcache/memcache.inc 2009-07-02 00:15:17.000000000 -0400 @@ -118,3 +118,100 @@ function cache_clear_all($cid = NULL, $t function memcache_clone($object) { return version_compare(phpversion(), '5.0') < 0 ? $object : clone($object); } + +/** + * + * Allows memcache & authcache dual functionality under the memcache module. + * + */ + +function page_cache_fastpath() { + global $base_root, $cache, $conf; + + // User is logged in but their role should not receive any cached pages + // (i.e., cached anonymous pages, since they have no authcache key) + if(isset($_COOKIE['drupal_user']) && !isset($_COOKIE['authcache'])) { + return FALSE; + } + + if (empty($_POST) && !isset($_COOKIE['nocache'])) { + + // Connect to database if 'db' engine selected + if($conf['cacherouter']['default']['engine'] == 'db') { + require_once './includes/database.inc'; + db_set_active(); + } + + if (!isset($cache)) { + $key = (isset($_COOKIE['authcache']) && $_COOKIE['authcache']) ? $_COOKIE['authcache'] : ''; + $page = cache_get($key . $base_root . request_uri(), 'cache_page'); + if (!empty($page)) { + + // Set HTTP headers in preparation for a cached page response. + + // The following headers force validation of cache: + header("Expires: Sun, 19 Nov 1978 05:00:00 GMT"); + header("Cache-Control: must-revalidate"); + + // Visitors can keep a local cache of the page, but must revalidate + // it on every request. Then, they are given a '304 Not Modified' + // response with no body as long as they say page has not been modified. + $last_modified = gmdate('D, d M Y H:i:s', $page->created) .' GMT'; + + // See if the client has provided the required HTTP caching header + // (No need for ETag; resolution of HTTP date value is sufficient) + $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE; + + if ($if_modified_since == $last_modified) { + + // Save cache benchmark + if(isset($_COOKIE['authcache_debug'])) { + setcookie('cache_render',timer_read('page')); + } + + header('HTTP/1.1 304 Not Modified'); + return TRUE; + } + + // Time from when page was saved to cache + header("Last-Modified: $last_modified"); + + // Send the original request's headers. + $headers = explode("\n", $page->headers); + foreach ($headers as $header) { + header($header); + } + + // Checking if first chars are compressed (always the same pattern for every header) + if (substr($page->data, 0,3) == "\x1f\x8b\x08") { + + // Determine if the browser accepts gzipped data. + if (@strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === FALSE && function_exists('gzencode')) { + // Strip the gzip header and run uncompress. + $page->data = gzinflate(substr(substr($page->data, 10), 0, -8)); + } + elseif (function_exists('gzencode')) { + // Send gzip header to the browser + header('Content-Encoding: gzip'); + } + } + + // Save cache benchmark + if(isset($_COOKIE['authcache_debug'])) { + setcookie('cache_render',timer_read('page')); + } + + print $page->data; + return TRUE; + } + } + } + + // Cache was temporarily disabled (most likely from drupal_set_message()/drupal_goto() redirect) + if(isset($_COOKIE['nocache_temp'])) { + setcookie('nocache', '', time() - 36000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); + setcookie('nocache_temp', '', time() - 36000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); + } + + return FALSE; +}