Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created January 24, 2013 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/4616240 to your computer and use it in GitHub Desktop.
Save westonruter/4616240 to your computer and use it in GitHub Desktop.
Patch to ensure that Batcache never returns a negative max-age which occurs if the request includes an If-Modified-Since header that is not equal to the cached response's Last-Modified time.
diff --git a/wp-content/advanced-cache.php b/wp-content/advanced-cache.php
index 83f24ee..4d01cd1 100644
--- a/wp-content/advanced-cache.php
+++ b/wp-content/advanced-cache.php
@@ -338,7 +338,7 @@ if ( isset($batcache->cache['time']) && ! $batcache->genlock && time() < $batcac
// Use the batcache save time for Last-Modified so we can issue "304 Not Modified"
if ( $batcache->cache_control ) {
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $batcache->cache['time'] ) . ' GMT', true );
- header('Cache-Control: max-age=' . ($batcache->max_age - time() + $batcache->cache['time']) . ', must-revalidate', true);
+ header( 'Cache-Control: max-age=' . max(0, $batcache->max_age - time() + $batcache->cache['time']) . ', must-revalidate', true );
}
// Add some debug info just before </head>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment