Wp-rocket: Auto-Compatibility with SpinUpWP Hosting

Created on 29 Apr 2019  ·  14Comments  ·  Source: wp-media/wp-rocket

There is a new hosting from Delicious Brain guys:
https://spinupwp.com/

The server caching system is NGINX and we could do an automatic compatibility like we do with other WordPress hostings to avoid purging caching issue.

3rd party compatibility [S] feature request cache documentation

Most helpful comment

Did testing on our sample site there. Everything is straightforward and not much different from what we do for other hostings

Scope a solution ✅

  • Create a third party subscriber class in inc/ThirdParty/Hostings/, SpinUpWP
  • Instantiate the class in the ThirdParty\ServiceProvider
  • Add the subscriber to the common subscribers list in Plugin::init_common_subscribers()
  • Use getenv( 'SPINUPWP_CACHE_PATH' ) in get_subscribed_events() to determine if the NGINX page cache is enabled
  • Use the following as a sample to add necessary hooks and callbacks:

    • add_filter( 'do_rocket_generate_caching_files', '__return_false' ); to disable WP Rocket cache creation

    • add_filter( 'rocket_display_varnish_options_tab', '__return_false' ); to disable display of the Varnish add-on

    • add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array' ); to prevent issue with mandatory cookies system with server page cache

    • remove_action( 'switch_theme', 'rocket_clean_domain' ); to prevent a double clear of the cache, since it's already performed by their plugin

    • Call spinupwp_purge_site() on after_rocket_clean_domain, to make sure the server cache is cleared when the user tries to purge the cache from the admin bar or the clear cache button on the WP Rocket dashboard

add_action( 'after_rocket_clean_domain', function() {
    if ( function_exists( 'spinupwp_purge_site' ) ) {
    spinupwp_purge_site();
    }
} );

Estimate the effort ✅

Effort [S]. Writing the code and the tests will be simple, as there is almost no custom logic in there.

The SpinUpWP plugin is available on https://wordpress.org/plugins/spinupwp/ if we want to install it as part of our integration tests suite.

All 14 comments

+1 on this

A customer has reached out to us about this.

For the SpinUpWP beta, their support said that he should be using either WP Rocket or their caching system.

So, our compatibility should probably include:

  • Disabling our page caching, when their caching is active.
  • Keeping the caches in sync.

Related ticket
https://secure.helpscout.net/conversation/905599500/116384/

@webtrainingwheels it was great meeting you at WCUS! We would love to see compatibility for SpinupWP built directly into WP Rocket.

All servers deployed via SpinupWP that have page caching enabled will have the SPINUPWP_CACHE_PATH environment variable set. The variable is added/removed as and when the page cache is toggled on/off. It will be safe to disable WP Rocket's page caching is that variable is set, using a check such as:

if ( getenv( 'SPINUPWP_CACHE_PATH' ) ) {
    // Actions to disable page caching
}

We have the following helper functions for purging the SpinupWP page cache, when our WordPress plugin is installed. For safety, those functions should be wrapped in function_exists just in case our WordPress plugin isn't installed as we don't enforce usage.

https://github.com/deliciousbrains/spinupwp-plugin/blob/develop/functions.php

We also have the following actions available for when the page cache is cleared via our own WordPress plugin:

https://github.com/deliciousbrains/spinupwp-plugin/blob/develop/src/Cache.php#L252

That should be everything required to get compatibility working. We'll be reaching out via email to get you an account setup on SpinupWP for testing.

Cheers!

+1 on this.

Disabling WP Rocket caching can easily be done by adding:

add_filter( 'do_rocket_generate_caching_files', '__return_false' );

Otherwise you could use a hook which fires a SpinupWP cache purge when WP Rocket one is done:

add_action('after_rocket_clean_domain','spinupwp_purge_site',10,0);

function spinupwp_purge_site() {
        return spinupwp()->cache->purge_page_cache();
}

@A5hleyRich Thanks so much for your reply :) We also received the test account info from your team.
@arunbasillal See https://secure.helpscout.net/conversation/1000139013/130448?folderId=377610 for info re: the test account

+1 for this.

+1 for this

Thank you @annejan89 for the cache disabling code.

Without WP Rocket, just SpinupWP and full page caching I was getting a C on pagespeed. Adding in WP Rocket and perfmatters I was able to get that up to an A.

Built in compatibility would be awesome.

I've just contacted SpinUpWP to get a test account. If we have it soon, we can keep the implementation for 3.6.2.

@wp-media/wprocketplugin I guess we can start to work on this compatibility.

All info you need to know are here:
https://github.com/wp-media/wp-rocket/issues/1678#issuecomment-552383605

Website URL and access are available into Bitwarden

@GeekPress I'm going to move this to needs: discovery in order to give us the space to do some research, discussion, prototyping. Then we'll be in a better position to be more accurate with our grooming solution and effort estimate.

@GeekPress @arunbasillal Update:

@Tabrisrp will lead the discovery and grooming effort for this user story and all of the web hosts we will make compatible with Rocket.

Did testing on our sample site there. Everything is straightforward and not much different from what we do for other hostings

Scope a solution ✅

  • Create a third party subscriber class in inc/ThirdParty/Hostings/, SpinUpWP
  • Instantiate the class in the ThirdParty\ServiceProvider
  • Add the subscriber to the common subscribers list in Plugin::init_common_subscribers()
  • Use getenv( 'SPINUPWP_CACHE_PATH' ) in get_subscribed_events() to determine if the NGINX page cache is enabled
  • Use the following as a sample to add necessary hooks and callbacks:

    • add_filter( 'do_rocket_generate_caching_files', '__return_false' ); to disable WP Rocket cache creation

    • add_filter( 'rocket_display_varnish_options_tab', '__return_false' ); to disable display of the Varnish add-on

    • add_filter( 'rocket_cache_mandatory_cookies', '__return_empty_array' ); to prevent issue with mandatory cookies system with server page cache

    • remove_action( 'switch_theme', 'rocket_clean_domain' ); to prevent a double clear of the cache, since it's already performed by their plugin

    • Call spinupwp_purge_site() on after_rocket_clean_domain, to make sure the server cache is cleared when the user tries to purge the cache from the admin bar or the clear cache button on the WP Rocket dashboard

add_action( 'after_rocket_clean_domain', function() {
    if ( function_exists( 'spinupwp_purge_site' ) ) {
    spinupwp_purge_site();
    }
} );

Estimate the effort ✅

Effort [S]. Writing the code and the tests will be simple, as there is almost no custom logic in there.

The SpinUpWP plugin is available on https://wordpress.org/plugins/spinupwp/ if we want to install it as part of our integration tests suite.

This auto-compatibility essentially disables WP Rocket page caching when SpinupWP's page cache is enabled, and clears the SpinupWP page cache when we use the WP Rocket "clear cache". Nice! 👍

In addition to that approach, it would be great if there were an option (or just documentation) to use WP Rocket's cache via SpinupWP / nginx try_files.

I mention this because it may be faster than SpinupWP's page cache, as SpinupWP's @A5hleyRich found with Simple Cache + nginx try_files. And if you think about it, anyone using WP Rocket may be inclined to want to use the WP Rocket features to the fullest extent, including the page cache.

Documenting these 2 approaches will educate users on how page caching works, whether it's SpinupWP's or WP Rocket's that's being used.

I see you blog about SpinupWP + nginx try_files here and link to the Rocket-Nginx configuration.

So, essentially clarifying all this somehow in the documentation or through the WP Rocket interface.

Was this page helpful?
0 / 5 - 0 ratings