Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For 'wp cache type', use a standard information function, if available, rather than class-sniffing #5735

Open
1 task done
OllieJones opened this issue Jan 31, 2023 · 1 comment

Comments

@OllieJones
Copy link

OllieJones commented Jan 31, 2023

Feature Request

wp cache type retrieves and displays the type of persistent object cache. Make it more easily extensible.

Describe your use case and the problem you are facing

For yet another persistent object cache implementation, this one via SQLite (https://github.com/OllieJones/sqlite-object-cache) it would be nice if thewp cache type command returned something more useful than Unknown.

Describe the solution you'd like

It uses an if / else if cascade in wp_get_cache_type() starting at https://github.com/wp-cli/wp-cli/blob/main/php/utils-wp.php#L255 to look for implementation specifics for each known type of cache and guess the cache type.

Proposal: change near line 256 to add the following bit of code. This will use a method in the cache implementation if it's available to get the cache type.

  // Use the get_cache_type method if the cache implements it.
 if ( method_exists( $wp_object_cache, 'get_cache_type' ) ) {
	  $message = $wp_object_cache->get_cache_type();
  
  // Test for Memcached PECL extension memcached object cache (https://github.com/tollmanz/wordpress-memcached-backend)
  } elseif ( isset( $wp_object_cache->m ) && $wp_object_cache->m instanceof \Memcached ) {
    ...

This allows future object cache implementations (like mine) to have support from the wp cache type command without needing to embed any more implementation specifics in utils-wp.php. And, future releases of existing caches can easily adapt.

OllieJones added a commit to OllieJones/sqlite-object-cache that referenced this issue Feb 1, 2023
@danielbachhuber
Copy link
Member

Thanks for the suggestion, @OllieJones !

We generally try to mirror core's implementation as much as possible. If core implemented a get_cache_type() method on the main WP_Object_Cache class, we could call that.

Until then, we'd be happy to add some detection for your object cache drop-in. There aren't so many object cache drop-ins that maintaining the list is a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants