Users: Cache database queries within WP_User_Query class.

Cache the results of database queries within `WP_User_Query` class. Only cache queries that are requesting 3 or less fields so that caches are not storing full user objects. Cache results are stored in a new global cache group named `users-queries`. Add a new parameter to `WP_User_Query` called `cache_results` to allow developers to opt out of a receiving cached results. `cache_results` parameter defaults to true. Also add a new helper function called `wp_cache_set_users_last_changed`, similar to `wp_cache_set_posts_last_changed` that incroments last changed value in cache group `users`.  Ensure that `wp_cache_set_users_last_changed` is called whenever user / user meta is modified for proper cache invalidation. 

Props johnjamesjacoby, spacedmonkey, westi, dd32, strategio, srikanthmeenakshi, OllieJones, khoipro, rjasdfiii, flixos90, mukesh27, peterwilsoncc. 
Fixes #40613.

git-svn-id: https://develop.svn.wordpress.org/trunk@55657 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2023-04-18 11:48:46 +00:00
parent e5057af16e
commit 19bd759db5
8 changed files with 898 additions and 19 deletions

View File

@@ -412,6 +412,7 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
'usermeta',
'user_meta',
'userslugs',
'users-queries',
)
);