WordPress.org

Ready to get started?Download WordPress

Forums

WP Super Cache
Whole cache deleted (9 posts)

  1. arjenschat
    Member
    Posted 3 years ago #

    Every once in a while the whole cache is gone.
    I've got 2 front-end machines running, both on the exact same date, time and timezone.
    How can I debug this, or how can I disable the Garbage Collection.

  2. Donncha O Caoimh
    Member
    Plugin Author

    Posted 3 years ago #

    Do you have "Clear all cache files when a post or page is published." checked?

  3. arjenschat
    Member
    Posted 3 years ago #

    "Clear all cache files when a post or page is published" is not checked

  4. Donncha O Caoimh
    Member
    Plugin Author

    Posted 3 years ago #

    You could set the expiry time to a really long interval too, and if you're using Preload, enable "Preload mode" so GC is disabled on Supercache files.

  5. arjenschat
    Member
    Posted 3 years ago #

    Alright I can try that.

    Where is the garbage collection initiated in the code? I'd like to move this to a cron script, so it will never be called during a page load.

  6. arjenschat
    Member
    Posted 3 years ago #

    Its running in preload mode, the expire is 720000 seconds, Clear all cache files when a post or page is published is not checked.

    Still the whole cache is deleted. Can you tell me which function is responsible for clearing the cache? I'll disable it in the code to see if an other plugin is deleting stuff, and from where it is called, with a xdebug stack trace etc.

  7. arjenschat
    Member
    Posted 3 years ago #

    Donncha,

    After a couple of hours debugging:
    On the Super cache admin panel, "Clear all cache files when a post or page is published" is not checked
    But "Only refresh current page when comments made" was not checked. Both options feel the same to me though.

    I recommend putting these underneath each other in the admin panel.

    Even though the refresh single page is selected, there is still a case where the whole cache will be reset, no matter what option you use.

    As you will see:

    In wp-cache-phase2.php, there is this piece of code:

    if ( isset( $wp_cache_refresh_single_only ) && $wp_cache_refresh_single_only && strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-comments-post.php' ) ) {
    	if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_change: comment detected. only deleting post page.", 4 );
    	$all = false;
    } else {
    	$all = true;
    }

    So the url must contain wp-comments-post.php. But a request to /xmlrpc.php will also call the following function sequence:
    pingback_ping > wp_new_comment > wp_insert_comment > wp_update_comment_count > wp_update_comment_count_now > do_action > call_user_func_array > wp_cache_post_change > wp_cache_post_id_gc > prune_super_cache

    Effectively pruning the whole cache.

    I recommend changing it into:

    if ( isset( $wp_cache_refresh_single_only ) && $wp_cache_refresh_single_only &&
    (strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-comments-post.php' )
     ||
     strpos( $_SERVER[ 'REQUEST_URI' ], 'xmlrpc.php' ) )
     ) {
  8. arjenschat
    Member
    Posted 3 years ago #

    It look like there are a lot more cases/ pages that will result in a call to the prune_super_cache function. Like editing you buddy press profile for instance.
    So I removed the whole REQUEST_URI check:

    if ( isset( $wp_cache_refresh_single_only ) && $wp_cache_refresh_single_only ) {
  9. Donncha O Caoimh
    Member
    Plugin Author

    Posted 3 years ago #

    Unfortunately the post_change() function is called by many things as you've found out but the options above ("Clear all cache files when a post or page is published" and "Only refresh current page when comments made") are very different.

    The $all that's set to true only causes the homepage to be deleted when this function is called (there's an "index.html" at the end of the directory passed to prune_super_cache()) so I don't know how all your cache files were deleted.

    Can you error_log() the directory passed to prune_super_cache()?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic