Support WP-Stash in 'wp cache type'
Greetings.
I just looked around the wp cache type command after seeing it returns "Unknown" in our WP instances running WP Stash. I think it would be pretty useful if we could see that a site is indeed running WP-Stash - and possibly which driver is in use.
I see that determining the cache type is a "manual" process that checks for the specifics of several implementations. So would you be supportive of adding WP Stash to the list of implementations to check against?
The most basic check would probably be class_exists('Inpsyde\WpStash\WpStash') and it could return get_class( WpStash::instance()->driver() ). This would yield the FQCN of the StashPHP driver that is currently being used.
I hope you consider this a worthwhile addition - which I'd happily PR your way.
As a side note: Wouldn't it make sense to provide a generic way for implementations to TELL wp-cli what's being used? The ideal solution would be of course if WP-Core had such a thing on offer, but in the absence of this: is there an inherent problem with checking for the existence of $wp_object_cache->type - or maybe even calling wp_cache_type() if it exists?
In addition, maybe you could return 'Unknown: ' . get_class( $wp_object_cache ), so users with entirely custom solutions would at least get some result.
Thanks for the suggestion, @Biont !
I'd be happy to accept a PR for what you're suggesting.
As a side note: Wouldn't it make sense to provide a generic way for implementations to TELL wp-cli what's being used? The ideal solution would be of course if WP-Core had such a thing on offer, but in the absence of this: is there an inherent problem with checking for the existence of
$wp_object_cache->type- or maybe even callingwp_cache_type()if it exists?
If a wp_cache_type() function existed in WordPress core, we could easily call it. I think it makes most sense to implement that formally first. It's not too much effort to maintain a list of object caches as there aren't many of them.
In addition, maybe you could return
'Unknown: ' . get_class( $wp_object_cache ), so users with entirely custom solutions would at least get some result.
Sure! Feel free to submit that as a second PR if you'd like.
Related https://github.com/wp-cli/wp-cli/issues/5735
wp cache type is broken with the SQLite Object Cache too.
I propose the following solution.
- New and revised persistent object cache plugins should provide a member function like this one. https://github.com/OllieJones/sqlite-object-cache/blob/0be3dbf6d6e9c7d3fb958964e1d169db191eeae0/assets/drop-in/object-cache.php#L1961
/**
* Return the cache type. For use by "wp-cli cache type" and other display code.
*
* @return string The type of cache, "SQLite".
*/
public function get_cache_type() {
return 'SQLite';
}
- WP-CLI should do the if (defined) call pattern on
$wp_object_cache->get_cache_type()to get its results... - Failing that, use the existing method.
This will prove more extensible that the current method.
- WP-CLI should do the if (defined) call pattern on
$wp_object_cache->get_cache_type()to get its results...
I think this needs to exist in core first. I don't want to introduce support for something official-looking, only to have core implement some different approach.
Opened https://core.trac.wordpress.org/ticket/58808 for that proposal
@swissspidy I worked a bit with @johnbillion on a spec for object cache information, in form of wp_cache_info(). Do you want to collaborate on this?
Yeah https://github.com/rhubarbgroup/wp-object-cache-info-spec was just mentioned to me today. I think I'm the wrong one to collaborate on that though, as I am not really familiar with all the object cache stuff.