Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPSC: Check that there is cached content to display in browser #40342

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Caching: make sure there is cache content to serve, even if the cache file was found
31 changes: 29 additions & 2 deletions projects/plugins/super-cache/wp-cache-phase2.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,44 @@ function wp_cache_serve_cache_file() {
if ( $wp_cache_gzip_encoding ) {
if ( file_exists( $file . '.gz' ) ) {
$cachefiledata = file_get_contents( $file . '.gz' );

if ( false === $cachefiledata ) {
wp_cache_debug( 'The cached gzip file could not be read. Must generate a new one.' );
return false;
}

wp_cache_debug( "Fetched gzip static page data from supercache file using PHP. File: $file.gz" );
} else {
$cachefiledata = gzencode( file_get_contents( $file ), 6, FORCE_GZIP );
$cachefiledata = file_get_contents( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents

if ( false === $cachefiledata ) {
wp_cache_debug( 'The cached file could not be read. Must generate a new one.' );
return false;
}

$cachefiledata = gzencode( $cachefiledata, 6, FORCE_GZIP );
wp_cache_debug( "Fetched static page data from supercache file using PHP and gzipped it. File: $file" );
}
} else {
$cachefiledata = file_get_contents( $file );

if ( false === $cachefiledata ) {
wp_cache_debug( 'The cached file could not be read. Must generate a new one.' );
return false;
}

wp_cache_debug( "Fetched static page data from supercache file using PHP. File: $file" );
}
} else {
// get dynamic data from filtered file
$cachefiledata = do_cacheaction( 'wpsc_cachedata', file_get_contents( $file ) );
$cachefiledata = file_get_contents( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents

if ( false === $cachefiledata ) {
wp_cache_debug( 'The cached file could not be read. Must generate a new one.' );
return false;
}

$cachefiledata = do_cacheaction( 'wpsc_cachedata', $cachefiledata );
if ( $wp_cache_gzip_encoding ) {
$cachefiledata = gzencode( $cachefiledata, 6, FORCE_GZIP );
wp_cache_debug( "Fetched dynamic page data from supercache file using PHP and gzipped it. File: $file" );
Expand Down Expand Up @@ -301,6 +327,7 @@ function wp_cache_serve_cache_file() {
}
header( 'Last-Modified: ' . $local_mod_time );
}

echo $cachefiledata;
exit();
} else {
Expand Down