wp_cache_flush() leads to loss of sitemap

#819003
  • Resolved Apcu
    Rank Math free

    One of our caching plugins has the following code, which is supposed to flush object cache:

    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;

    }

    Instead, after running the function, the following lines disappear from WP rewrite rules:

    “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

    And even if I type index.php?sitemap=1 directly, the sitemap still doesn’t show up. I have to flush permalinks to restore the sitemap.

    My question is: why running wp_cache_flush(); can affect Rankmath in this way?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,

    I understand the issue you are facing with the caching plugin and the impact it has on Rank Math’s sitemap. When you run wp_cache_flush(); using the provided code, it clears the object cache, which can lead to the loss of the sitemap rewrite rules in WordPress.

    The reason why running wp_cache_flush(); affects Rank Math in this way is that Rank Math relies on certain cached data to generate and display the sitemap correctly. By flushing the cache abruptly, the cached data that Rank Math needs to generate the sitemap is also cleared, causing the sitemap to disappear until you flush the permalinks to regenerate the necessary data.

    To prevent this issue, you may need to exclude the sitemap files generated by Rank Math from being cached by your caching plugin. This will ensure that the necessary data for the sitemap remains intact even after clearing the cache.

    If you continue to experience issues or have further questions, please feel free to reach out for more assistance.

    Thank you for bringing this concern to our attention.

    Sources:
    Why the Sitemap_Index.xml is Throwing a 404 Error » Rank Math
    Rank Math XML Sitemaps on NGINX Servers » Rank Math
    Rank Math Sitemap Issues and Their Fixes » Rank Math

    Apcu
    Rank Math free

    I would like to know which cached data in Rankmath exactly is being affected by wp_cache_flush(); so I can work with the author of the caching plugin and see if the problem can be circumvented.

    The sitemap is already excluded from caching.

    Apcu
    Rank Math free

    Any update on this?

    Apcu
    Rank Math free

    Since we don’t expect this to be resolved any time soon, our preferred solution is to switch to the more robust implementation of sitemap in post-5.5 Core WP.

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    Our plugin has 3 instances where it uses the function wp_cache_flush().

    1. In the permalink watcher for the WooCommerce module and it’s used to add the necessary rewrite rules when you enable options like the “Remove Base” for example.

    2. In the Analytics module when the action to clear the cache from Analytics is called which usually happens once every 7 days in the Free version.

    3. During the uninstall of the plugin to make sure that no transient cache is left being after removing the plugin.

    We don’t have any other instance of this function being called anywhere else inside the plugin.

    Hope that helps, and please do not hesitate to let us know if you need our assistance with anything else.

    Apcu
    Rank Math free

    That’s interesting to know, Ike, but doesn’t quite answer my question. I made it clear in my original post that wp_cache_flush(); was called by a caching plugin, not by Rank Math.

    Could you please try and think of potential reasons why another plugin calling wp_cache_flush(); would cause Rank Math to lose the 3 rewrite rules and make index.php?sitemap=1 returning blank page?

    There’s evidently a conflict with Rank Math since the caching plugin in question works perfectly with WP Core’s native wp-sitemap.xml.

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Apcu
    Rank Math free

    Many thanks for your kind offer. Although I’m not in a position to give your staff access to our backend, I can share the following information: the issue occurs when Rank Math is used in tandem with Super Page Cache for Cloudflare and APCu-based object-cache.php. Super Page Cache calls wp_cache_flush();, which, instead of flushing the (persistent) object cache, causes Rank Math to lose its sitemap.

    Since we’ve switched to WP’s native sitemap as a better solution, I’ll mark this as solved and it’s up to you whether you want to set up a testing environment to try and replicate the issue with a view to making Rank Math a more robust solution.

    I’d be happy to answer any queries in case you decide to investigate this.

    Hello,

    We understand that you are not able to share the affected site’s login information.

    We have shared the details you mentioned with our development team.

    If they have updates with regard to this caching conflict, we’ll let you know here.

    In the meantime, don’t hesitate to get in touch with us if you have any other questions.

Viewing 9 replies - 1 through 9 (of 9 total)

You must be logged in to reply to this ticket.