diff --git a/CHANGELOG.md b/CHANGELOG.md index f85cc22c..933860a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This is an alpha version! The changes listed here are not final. ### Added - Setup: Detect Jetpack Boost cache and suggest troubleshooting steps +- WP Super Cache: added WPSC_PRELOAD_POST_INTERVAL and WPSC_PRELOAD_LOOP_INTERVAL to modify preload timings ### Changed - Code Modernization: Replace usage of strpos() with str_contains() diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 5ede1706..69ac0bc2 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -5,8 +5,6 @@ * It has all the code for caching and serving requests. */ -define( 'WPSC_PRELOAD_POST_COUNT', 10 ); - // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_is_writable -- TODO: Fix or determine for sure that these should not be fixed. // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fwrite -- TODO: Fix or determine for sure that these should not be fixed. diff --git a/wp-cache.php b/wp-cache.php index 38b9e967..41e7adc8 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -45,6 +45,27 @@ unset( $wpsc_php_version ); } +/** + * Defines how many posts to preload per loop. + */ +if ( ! defined( 'WPSC_PRELOAD_POST_COUNT' ) ) { + define( 'WPSC_PRELOAD_POST_COUNT', 10 ); +} + +/** + * Defines the interval in seconds between preloading pages. + */ +if ( ! defined( 'WPSC_PRELOAD_POST_INTERVAL' ) ) { + define( 'WPSC_PRELOAD_POST_INTERVAL', 1 ); +} + +/** + * Defines the interval in seconds between preloading loops. + */ +if ( ! defined( 'WPSC_PRELOAD_LOOP_INTERVAL' ) ) { + define( 'WPSC_PRELOAD_LOOP_INTERVAL', 0 ); +} + function wpsc_init() { global $wp_cache_config_file, $wp_cache_config_file_sample, $wpsc_advanced_cache_dist_filename, $wp_cache_check_wp_config, $wpsc_advanced_cache_filename, $wpsc_promo_links; @@ -3470,7 +3491,7 @@ function wp_cron_preload_cache() { ) ); wp_cache_debug( "wp_cron_preload_cache: fetched $url" ); - sleep( 1 ); + sleep( WPSC_PRELOAD_POST_INTERVAL ); if ( ! wpsc_is_preload_active() ) { wp_cache_debug( 'wp_cron_preload_cache: cancelling preload process.' ); @@ -3505,6 +3526,7 @@ function wp_cron_preload_cache() { if ( $preload_more_taxonomies === true ) { wpsc_schedule_next_preload(); + sleep( WPSC_PRELOAD_LOOP_INTERVAL ); return true; } } elseif ( $c === 0 && $wp_cache_preload_email_me ) { @@ -3594,7 +3616,7 @@ function wp_cron_preload_cache() { wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) ); wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 ); ++$count; - sleep( 1 ); + sleep( WPSC_PRELOAD_POST_INTERVAL ); } if ( $wp_cache_preload_email_me && ( $wp_cache_preload_email_volume === 'medium' || $wp_cache_preload_email_volume === 'many' ) ) { @@ -3603,8 +3625,8 @@ function wp_cron_preload_cache() { } wpsc_schedule_next_preload(); - wpsc_delete_files( get_supercache_dir() ); + sleep( WPSC_PRELOAD_LOOP_INTERVAL ); } else { $msg = ''; wpsc_reset_preload_counter();