Created
January 24, 2013 00:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
See full writeup at http://wordpress.org/support/topic/if-modified-since-request-header-can-cause-a-cache-control-negative-max-age?replies=1