• Because CF Free doesn’t support cookie-bypass, and CF Super Page Cache (WPCSPC) doesn’t yet support a cookies-bypass filter either, have been looking into a workaround thanks to CF Workers via this plugin (ECHCW).

    At glance, ECHCW does the cookie-bypass thing and works reasonably well so far, but already noticed it has the following drawbacks:
    a) The Worker implementation still needs of the “cache-everything” page rule, otherwise CF-Cache-Status: DYNAMIC is returned for every response (at least for my use case)
    b) Also encountered issues of wp-admin getting cached, so had to add yet another page rule to fix that one too
    c) The Workers script implements a fine-grained cache purge based on KV Namespaces, but that CF facility isn’t free anymore, unfortunately. The other option available in the script is a “purge-everything” happening each time something gets updated at the origin, which is suboptimal and wasteful.

    Those shortcomings mesh well with WPCSPC’s strengths, and vice-versa, so it’s gainful for everyone to consider integrating both plugins (at least until WPCSPC gets ready with its own flavor of Workers).

    Looking at the code of the sidekick plugin that does the origin’s page-caching (CFPC), it easily becomes apparent the process of invoking the Worker is quite straightforward; CFPC just inserts this code during init to fire up everything else at the Edge:

    if( !is_user_logged_in() ) {
       header( 'x-HTML-Edge-Cache: cache,bypass-cookies=wp-|wordpress|comment_|woocommerce_' );
    } else {
       header( 'x-HTML-Edge-Cache: nocache' );
    }

    The remaining code of CFPC manages the various purge cases happening at WP, by setting and additional header('x-HTML-Edge-Cache: purgeall'), but as already stated above, purging that way isn’t of much use without a KV namespace, so WPCSPC API approach should apply anyway.

    Summarizing, WPCSPC could become ECHCW’s new and improved “sidekick” instead of CFPC, by only adding 2 lines of code in cache_controller.class.php, namely:

    if( $this->skip_cache )
        return;
    #-->
    if( !is_user_logged_in() )
        header('x-HTML-Edge-Cache: cache,bypass-cookies=wp-|wordpress|comment_|woocommerce_');
    #<--
    if( $this->is_url_to_bypass() ) {
        header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
        header("Cache-Control: post-check=0, pre-check=0", false);
        header("Pragma: no-cache");
        header("X-WP-CF-Super-Cache: no-cache");
        header('X-WP-CF-Super-Cache-Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
    #-->
        header('x-HTML-Edge-Cache: nocache');
    #<--
        $this->skip_cache = true;
        return;
    }

    It seems working well for me so far.

    HTH.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter alx359

    (@alx359)

    Skimming at cache_controller.class.php once again, figured a better place to insert the ECHCW cache header would be at the end of apply_cache() instead, like this:

    header_remove('Pragma');
    header_remove('Expires');
    header_remove('Cache-Control');
    header('Cache-Control: '.$this->get_cache_control_value());
    header("X-WP-CF-Super-Cache: cache");
    header("X-WP-CF-Super-Cache-Active: 1");
    header('X-WP-CF-Super-Cache-Cache-Control: '.$this->get_cache_control_value());
    #-->
    if( !is_user_logged_in() )
        header('x-HTML-Edge-Cache: cache,bypass-cookies=wp-|wordpress|comment_|woocommerce_');
    #<--

    And put the ECHCW nocache header in one more place within that same apply_cache() function:

    if ( $this->can_i_bypass_cache() ) {
        header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
        header("Cache-Control: post-check=0, pre-check=0", false);
        header("Pragma: no-cache");
        header("X-WP-CF-Super-Cache: no-cache");
        header('X-WP-CF-Super-Cache-Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
    #-->
        header('x-HTML-Edge-Cache: nocache');
    #<--
        return;
    }

    Anyway, let’s hope for your kind advise on this whole hack, Salvatore.

    Plugin Contributor Salvatore Fresta

    (@salvatorefresta)

    Hi @alx359,
    do you want become a beta tester for the upcoming version? If yes, drop me a line via email so I can give you the lastest version.

    You can test the new worker mode, fallback cache and other new features ??

    Thread Starter alx359

    (@alx359)

    Perfect, thanks! I shall contact you privately.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[FIX] Interoperability with CF Workers plugin’ is closed to new replies.