0

Today I noticed that \WP_CLI\Utils\wp_clear_object_cache() has been marked as deprecated in WP-CLI 1.5.0. The release notes don't mention anything about it. What should be used, instead? Do I still need to take care of flushing the cache myself or is it handled automatically now, like mentioned here?

1 Answer 1

1

The function wp_cache_flush() should help you but is not the same one.

The function runs on the global $wp_object_cache and set a new empty array, different to the WP CLI deprecated function wp_clear_object_cache for different keys of the global var.

function wp_clear_object_cache() {
    global $wpdb, $wp_object_cache;

    $wpdb->queries = [];

    if ( ! is_object( $wp_object_cache ) ) {
        return;
    }

    // The following are Memcached (Redux) plugin specific (see https://core.trac.wordpress.org/ticket/31463).
    if ( isset( $wp_object_cache->group_ops ) ) {
        $wp_object_cache->group_ops = [];
    }
    if ( isset( $wp_object_cache->stats ) ) {
        $wp_object_cache->stats = [];
    }
    if ( isset( $wp_object_cache->memcache_debug ) ) {
        $wp_object_cache->memcache_debug = [];
    }
    // Used by `WP_Object_Cache` also.
    if ( isset( $wp_object_cache->cache ) ) {
        $wp_object_cache->cache = [];
    }
}

Note: The deprecated flag should be wrong, and the maintenance team will change them in a future version. That is information after a small talk with the team.

4
  • Thank you! the WP_CLI\Utils\ wp_clear_object_cache doesn't just clear the full cache, it instead only deletes certain properties. Did they decide it's not necessary? I can't find an official opinion on this anywhere...
    – rassoh
    Apr 6, 2022 at 10:30
  • I ask Alain (WP CLI Dev Lead) and he means, the method is okay. Maybe the deprecated flag is wrong. He will check them. The difference between these two functions is clear. see github.com/wp-cli/wp-cli/pull/4615/files
    – bueltge
    Apr 6, 2022 at 11:58
  • Thank you! Any news on this from Alain?
    – rassoh
    Apr 20, 2022 at 7:42
  • 1
    Not necessary, because he will leave this function and remove the flag deprecated in one of the next releases.
    – bueltge
    Apr 21, 2022 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.