-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New helper functions, wp_cache_*_salted #8728
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
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
LGTM! I'd approve this if I'd had the permissions. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @jonnynews. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
felixarntz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spacedmonkey @tillkruss I really like where this is going.
I think we should consider implementing two helper functions to read and write cache keys with $last_changed awareness, so that that logic is abstracted and doesn't need to be duplicated in all these places. Doing so would make the logic updates needed in each query class minimal.
Excellent idea! |
Introduced `wp_cache_get_query_data` and `wp_cache_set_query_data` to handle cached query data with freshness validation. Refactored various classes, functions, and queries to use these standardized methods for improved readability and maintainability while ensuring cache consistency.
cd7f5cb to
e440510
Compare
…ery` for enhanced query cache handling.
…and consistency.
last_changed check.…consistency and clarity.
…ery cache validation
…ion and update test cases for consistency.
peterwilsoncc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source looks great, I've added a nit pick inline and some notes on the tests.
peterwilsoncc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me/
I'll do some further manual testing but the test suite looks solid so I'll only come back if I discover any bugs while testing. If you don't hear from me assume it's good to go.
felixarntz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spacedmonkey LGTM!
Only a few nit-picks on documentation, there are still obsolete mentions of the old "query data" approach in the descriptions on the new functions.
Preemptively approving, but we should fix those :)
Co-authored-by: Felix Arntz <flixos90@gmail.com> Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
|
I've committed @felixarntz and @mukeshpanchal27's suggestions and merged in trunk. I'm still a little concerned about passing in the salt values rather than the last changed names. It requires a developer remember to maintain order when generating the salted value, for example the following will result in different underlying cache keys being hit. $salts = array(
wp_cache_get_last_changed( 'group1' ),
wp_cache_get_last_changed( 'group2' ),
);
$cached = wp_cache_get_salted( 'key', 'group', $salt );
$salts = array(
wp_cache_get_last_changed( 'group2' ),
wp_cache_get_last_changed( 'group1' ),
);
$cached = wp_cache_get_salted( 'key', 'group', $salt );If instead we pass the group names for the sort( $salt );
$real_salt = array();
foreach ( $salt as $s ) {
$real_salt[] = wp_cache_get_last_changed( $salt );
}A compromise possibility may be to accept the salts with keys and do a $salt = array(
'posts' => wp_cache_get_last_changed( 'posts' ),
'terms' => wp_cache_get_last_changed( 'terms' ),
);I don't know that I am invested enough to consider this a blocker but if it's something we can optimise while working on this ticket, it would be preferable than doing so in the future. |
+1 |
|
@peterwilsoncc I can see an argument for a helper function to make the salt specifically for wp-core queries, but sorting $salt = wp_cache_get_last_changed_salt([ 'users', 'comments' ])
$cached = wp_cache_get_salted( 'some-query', 'user-queries', $salt );
function wp_cache_get_last_changed_salt( $groups ) {
if (! is_array( $groups ) ) {
$groups = [$groups];
}
sort( $groups );
return array_map(function ( $group ) {
return wp_cache_get_last_changed( $salt )
});
} |
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
peterwilsoncc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see an argument for a helper function to make the salt specifically for wp-core queries, but sorting
$saltseems risky and passing group names towp_cache_get_salted()seems incorrect to me. Just my ¢2.
I'm happy to listen to your two cents, you deal with these APIs far more frequently than I. @spacedmonkey, do you want to do the commit honours?
I think we might be over thinking this a little. My perf to just commit this and we can see key sort later if we feel it is needed. If we do add keys to the salts, then we could just do this. Above could be adde later without any sort of break. |
4da5bfe to
9b390e1
Compare
|
Commited in r60697. |
Create new helper functions wp_cache_*_salted, that improve cache invalidation, by re-using cache keys.
Trac ticket: https://core.trac.wordpress.org/ticket/59592
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.