I couldn’t find a better plugin so I decided to fix this in wp supercache. This patch is applied to my live version on my site and is so far working fine and solves all problems while not changing any functionality:
Index: wp-content/plugins/wp-super-cache/wp-cache-phase2.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- wp-content/plugins/wp-super-cache/wp-cache-phase2.php (revision 3760)
+++ wp-content/plugins/wp-super-cache/wp-cache-phase2.php (revision )
@@ -93,7 +93,7 @@
return false;
}
- if ( $wp_cache_no_cache_for_get && false == empty( $_GET ) ) {
+ if ( $wp_cache_no_cache_for_get && wp_cache_is_get_query() ) {
wp_cache_debug( 'Non empty GET request. Caching disabled on settings page. ' . wpsc_dump_get_request(), 1 );
return false;
}
@@ -145,8 +145,8 @@
if ( false == file_exists( $file ) ) {
wp_cache_debug( "No Super Cache file found for current URL: $file" );
return false;
- } elseif ( false == empty( $_GET ) ) {
- wp_cache_debug( 'GET array not empty. Cannot serve a supercache file. ' . wpsc_dump_get_request() );
+ } elseif ( wp_cache_is_get_query() ) {
+ wp_cache_debug( 'Non empty GET request. Cannot serve a supercache file. ' . wpsc_dump_get_request() );
return false;
} elseif ( wp_cache_get_cookies_values() != '' ) {
wp_cache_debug( 'Cookies found. Cannot serve a supercache file. ' . wp_cache_get_cookies_values() );
@@ -1397,7 +1397,7 @@
return false;
}
- if ( ! empty( $_GET ) ) {
+ if ( wp_cache_is_get_query() ) {
wp_cache_debug( 'Supercache caching disabled. Only using wp-cache. Non empty GET request. ' . wpsc_dump_get_request(), 5 );
$super_cache_enabled = false;
}
@@ -1878,7 +1878,7 @@
if ( defined( 'DONOTCACHEPAGE' ) ) {
wp_cache_debug( 'DONOTCACHEPAGE defined. Caching disabled.', 2 );
$cache_this_page = false;
- } elseif ( $wp_cache_no_cache_for_get && ! empty( $_GET ) ) {
+ } elseif ( $wp_cache_no_cache_for_get && wp_cache_is_get_query() ) {
wp_cache_debug( 'Non empty GET request. Caching disabled on settings page. ' . wpsc_dump_get_request(), 1 );
$cache_this_page = false;
} elseif ( $_SERVER["REQUEST_METHOD"] == 'POST' || !empty( $_POST ) || get_option( 'gzipcompression' ) ) {
@@ -2107,7 +2107,7 @@
$dir = get_current_url_supercache_dir();
$supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $home_url[ 'host' ]);
- if ( ! empty( $_GET ) || isset( $wp_super_cache_query[ 'is_feed' ] ) || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) {
+ if ( wp_cache_is_get_query() || isset( $wp_super_cache_query[ 'is_feed' ] ) || ( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) ) {
wp_cache_debug( 'Supercache disabled: GET or feed detected or disabled by config.', 2 );
$super_cache_enabled = false;
}
@@ -2122,7 +2122,7 @@
}
if( $super_cache_enabled ) {
- if ( wp_cache_get_cookies_values() == '' && empty( $_GET ) ) {
+ if ( wp_cache_get_cookies_values() == '' && !wp_cache_is_get_query() ) {
wp_cache_debug( 'Anonymous user detected. Only creating Supercache file.', 3 );
$supercacheonly = true;
}
@@ -3301,6 +3301,17 @@
wp_cache_debug( 'GC Watcher: scheduled new gc cron.', 5 );
schedule_wp_gc();
}
+}
+
+function wp_cache_is_get_query() {
+ static $is_get_query = null;
+
+ if (null === $is_get_query) {
+ $request_uri = parse_url($_SERVER['REQUEST_URI']);
+ $is_get_query = $request_uri && !empty($request_uri['query']);
+ }
+
+ return $is_get_query;
}
if ( ! function_exists( 'apache_request_headers' ) ) {
-
This reply was modified 3 years, 4 months ago by
emilycestmoi.
Interesting problem. Do you have this setting enabled?
“Don’t cache pages with GET parameters.”
Checking REQUEST_URI is probably a better way of doing this but I am sure that someone out there is relying on this behaviour and setting a $_GET variable to stop a page caching.
Hi! The default behavior is that if “Don’t cache pages with GET parameters” is unchecked then the plugin will use the fallback php file caching, not static file supercaching. The plugin is currently checking $_GET and preventing supercaching whether the “Don’t cache pages with GET parameters” is checked or not.
The correct way to avoid supercaching is to check REQUEST_URI as is done in my patch above. I have been using this patch now for 1 month on my live site with no issues at all, and it continues to successfully use static file supercaching on all 500000+ pages that are auto generated.
Thanks @emilycestmoi. I’ve prepared a PR based on your code. I’ll merge it next week unless you see anything wrong with it? I don’t use add_rewrite_rule() so I’d appreciate your eyes on it.
https://github.com/Automattic/wp-super-cache/pull/813