settings = Boost_Cache_Settings::get_instance(); } public function setup() { Garbage_Collection::setup(); add_action( 'jetpack_boost_page_output_changed', array( $this, 'handle_page_output_change' ) ); } public function register_data_sync( Data_Sync $instance ) { $page_cache_schema = Schema::as_assoc_array( array( 'bypass_patterns' => Schema::as_array( Schema::as_string() ), 'logging' => Schema::as_boolean(), ) ); $page_cache_error_schema = Schema::as_assoc_array( array( 'code' => Schema::as_string(), 'message' => Schema::as_string(), 'dismissed' => Schema::as_boolean()->fallback( false ), ) )->nullable(); $instance->register_readonly( 'cache_debug_log', Schema::as_unsafe_any(), array( Logger::class, 'read' ) ); $instance->register_readonly( 'cache_engine_loading', Schema::as_unsafe_any(), array( Boost_Cache::class, 'is_loaded' ) ); $instance->register( 'page_cache', $page_cache_schema, new Page_Cache_Entry() ); // Page Cache error $instance->register( 'page_cache_error', $page_cache_error_schema ); $instance->register_action( 'page_cache', 'run-setup', Schema::as_void(), new Run_Setup() ); $instance->register_action( 'page_cache', 'clear-page-cache', Schema::as_void(), new Clear_Page_Cache() ); $instance->register_action( 'page_cache', 'deactivate-wpsc', Schema::as_void(), new Deactivate_WPSC() ); } public function handle_page_output_change() { $this->invalidate_cache(); // Remove the action so it doesn't run again during the same request. remove_action( 'jetpack_boost_page_output_changed', array( $this, 'handle_page_output_change' ) ); } private function invalidate_cache() { $cache = new Boost_Cache(); $cache->get_storage()->invalidate( home_url(), Filesystem_Utils::DELETE_ALL ); } /** * Runs cleanup when the feature is deactivated. */ public static function deactivate() { Garbage_Collection::deactivate(); Boost_Cache_Settings::get_instance()->set( array( 'enabled' => false ) ); Page_Cache_Setup::delete_advanced_cache(); } /** * The module is active if cache engine is loaded. * * @return bool */ public function is_ready() { return Boost_Cache::is_loaded(); } public static function is_available() { // Disable Page Cache on WoA and WP Cloud clients. // They already have caching enabled. if ( ( new Host() )->is_woa_site() || ( new Host() )->is_atomic_platform() ) { if ( Page_Cache_Setup::can_run_cache() ) { return true; } return false; } return true; } public static function get_slug() { return 'page_cache'; } }