• Resolved p15h

    (@prestonwordsworth)


    I reported this issue previously in an unresolved thread. I now have more information on the precise flow.

    After hitting ‘Purge CR cache’ for any page, the following three lines at the head of wp rewrite rules also disappear, leading to 404 at /sitemap_index.xml:

    "sitemap_index\.xml$",index.php?sitemap=1,other                                                                                        
    "([^/]+?)-sitemap([0-9]+)?\.xml$",index.php?sitemap=$matches[1]&sitemap_n=$matches[2],other                                            
    "([a-z]+)?-?sitemap\.xsl$",index.php?xsl=$matches[1],other

    The rewrite rules can be retrieved with the command wp rewrite list --format=csv.

    Saumya, being more familiar with the plugin’s codebase than I am, do you have any idea how this happens?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor iSaumya

    (@isaumya)

    Hi,
    That is very odd as on purge cache the plugin doesn’t rewrite anything. Also, I have this plugin across numerous site running rankmath without any issues.

    Can you please create a staging site only with this plugin and Rankmath to see if you can replicate the issue?

    Thread Starter p15h

    (@prestonwordsworth)

    If there’s nothing in the code that suggests a cause, let me try and collect more information and report back.

    Plugin Contributor iSaumya

    (@isaumya)

    yes, please

    Thread Starter p15h

    (@prestonwordsworth)

    I’ve been able to make some progress this week.

    Both Rankmath and this plugin on our machine are now the latest versions. And I’ve also verified that the 404 only happens when a Purge cache link is manually hit; auto purge triggered by an edit doesn’t cause the sitemap to disappear.

    Interestingly, the 404 isn’t just about the loss of three wp rewrite rules, as I’d previously assumed. After a manual purge, even if I visit the URI index.php?sitemap=1 directly (ie not relying on pretty link & wp rewrite), the sitemap doesn’t show up.

    So, for the next step, I’ll probably have a look at the code for triggering a manual purge.

    Thread Starter p15h

    (@prestonwordsworth)

    I’ve managed to narrow down the culprit to the following code in libs/cache_controller.class.php:

    function purge_object_cache() {

    if( !function_exists('wp_cache_flush') )
    return false;

    wp_cache_flush();

    $this->objects = $this->main_instance->get_objects();

    $this->objects['logs']->add_log('cache_controller::purge_object_cache', 'Purge object cache' );

    return true;

    }

    It causes the Rankmath sitemap to disappear when run as part of ajax_purge_single_post_cache, but not when run by cronjob as part of purge_cache_on_post_edit.

    So I was able to fix the problem by turning off the option ‘Automatically purge the object cache when Cloudflare cache is purged’.

    Thread Starter p15h

    (@prestonwordsworth)

    So the problem is caused by wp_cache_flush().

    And since on sites where persistent object cache is enabled, a call to wp_cache_flush() will be routed to wp-content/object-cache.php, I suspect the issue may have to do with the particular way wp_cache_flush() interacts with the wp-content/object-cache.php for APCu. On our machine, wp_cache_flush() obviously doesn’t actually flush APCu object cache; conversely, manually flushing APCu object cache never leads to disappearance of the sitemap.

    Saumya, could you share which plugins (APCu, Redis or Memcached) provide the wp-content/object-cache.php on your sites and whether triggering cache_controller::purge_object_cache from your end always results in the entire persistent object cache being deleted?

    Plugin Contributor iSaumya

    (@isaumya)

    If that is the cause then inside the plugin settings Advanced tab you can turn off object cache flush so the plugin won’t try to flus object cache.

    Thread Starter p15h

    (@prestonwordsworth)

    That certainly works. But I’m still curious about the cause behind it. Does object cache gets successfully flushed by this plugin on yours sites because you are using a different object cache than APCu?

    Thread Starter p15h

    (@prestonwordsworth)

    We solved the original issue by turning off Rank Math’s fragile implementation of sitemap and switching to the robust and more than adequate native sitemap of post-5.5 Core WP.

    The remaining issue is the incompatibility of this plugin’s purge_object_cache() with APCu-based object cache, for which I’ll open a separate thread.

    Plugin Contributor iSaumya

    (@isaumya)

    OK. But don’t think I can do anything about this.

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.