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

Add initial functionality and tests #1

Merged
merged 14 commits into from
Jan 2, 2024
Merged

Add initial functionality and tests #1

merged 14 commits into from
Jan 2, 2024

Conversation

dlh01
Copy link
Member

@dlh01 dlh01 commented Dec 26, 2023

This library provides PSR-16 implementations for WordPress projects. It includes adapters for caching data in the object cache, as transients, as options, and as post, term, or other object metadata.

Copy link
Member

@kevinfodness kevinfodness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work. Left some comments, suggestions, and questions, but nothing blocking. 🍣

if: github.event.pull_request.draft == false
uses: alleyinteractive/.github/.github/workflows/php-code-quality.yml@main
with:
php: 8.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend we use 8.2 here

if: github.event.pull_request.draft == false
uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main
with:
php: 8.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also

- main
types: [opened, synchronize, reopened, ready_for_review]

jobs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a good candidate to test out the strategy defined here: alleyinteractive/create-wordpress-project#63

Otherwise, we would have to mark as required each of the matrix jobs with their versions (4 total combinations).

Copy link
Member Author

@dlh01 dlh01 Dec 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read that issue and am not sure I understand it. I'll respond over there.

Scratch that, I read it again and now understand it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried giving each workflow a generic name in 5c46788, but it just made a mess. GitHub ran all the tests under the specific name defined in the upstream workflow anyway. I'm going to leave the next experiment to someone who knows how GHA works better than I do.

README.md Outdated
@@ -0,0 +1,55 @@
# PSR16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to make this "WP PSR-16" or something to indicate it's for WordPress specifically in the title.

"extra": {
"wordpress-autoloader": {
"autoload": {
"Alley\\": "src/alley/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this specific enough to this library? What about other libraries we maintain that have a namespace of Alley?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this doesn't prevent other libraries from autoloading files with the Alley namespace out of their respective src directories.

phpcs.xml Outdated
@@ -0,0 +1,49 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="alleyinteractive/wp-psr16" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XSD reference should be updated to the new repo home:

Suggested change
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="alleyinteractive/wp-psr16" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="alleyinteractive/wp-psr16" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">

ref: https://github.com/Automattic/VIP-Coding-Standards/pull/805/files

$out = $default;

foreach ( $get as $value ) {
$out = $value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that getMultiple would ever return more than one value for this key?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible, I guess, but only in the case of an implementation error against the spec. I'll update it just in case.

* @return bool True on success and false on failure.
*/
public function clear(): bool {
return false; // Not supported by default in WordPress.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't supported by default in memcached but there is a way to do this in Redis. Fine to keep as-is for now but we may want to consider a future enhancement where we could keep an inventory of cache keys that could be deleted on a clear operation (maybe in a separate database table even). That's a common enough problem that we run into where a generic solution would be excellent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in Slack, this is "not supported" in the sense that there is no built-in way to delete only the meta keys that have been saved by this library. The library could add support for clear() by adding its own manifest of cache keys that would then be deleted.

* @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
*/
public function getMultiple( iterable $keys, mixed $default = null ): iterable {
$metadata = get_metadata( $this->type, $this->id );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be misunderstanding, but does this library provide functionality for using an object cache implementation for metadata, or does it rely on the underlying WP implementation (e.g., get_metadata here would attempt to pull from WP's cache, which could be a memcached-backed object cache, but this library doesn't care)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in Slack, it's more the latter: The takeaway for this adapter is that object metadata itself is used as the cache data store. The fact that core also caches object metadata in the persistent object cache is an implementation detail on the part of core.

@dlh01 dlh01 merged commit 5ff4116 into main Jan 2, 2024
8 checks passed
@dlh01 dlh01 deleted the feature/0.1 branch January 2, 2024 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants