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

Support WP-Stash in 'wp cache type' #68

Open
Biont opened this issue Feb 19, 2021 · 7 comments
Open

Support WP-Stash in 'wp cache type' #68

Biont opened this issue Feb 19, 2021 · 7 comments

Comments

@Biont
Copy link

Biont commented Feb 19, 2021

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.

@danielbachhuber
Copy link
Member

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 calling wp_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.

@danielbachhuber
Copy link
Member

Related wp-cli/wp-cli#5735

@OllieJones
Copy link

wp cache type is broken with the SQLite Object Cache too.
I propose the following solution.

  1. 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';
		}
  1. WP-CLI should do the if (defined) call pattern on $wp_object_cache->get_cache_type() to get its results...
  2. Failing that, use the existing method.

This will prove more extensible that the current method.

@danielbachhuber
Copy link
Member

  1. 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.

@swissspidy
Copy link
Member

Opened https://core.trac.wordpress.org/ticket/58808 for that proposal

@tillkruss
Copy link

@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?

@swissspidy
Copy link
Member

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.

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

5 participants