Commit Graph

15 Commits

Author SHA1 Message Date
Sergey Biryukov df054f2dae Cache API: Validate cache key in `WP_Object_Cache` methods.
Some plugins may call the `wp_cache_*()` functions with an empty string, `false`, or `null` as cache key, usually as a result of not checking the return value of another function that's used as the key.

Previously, this was silently failing, leading to odd behavior at best and often breakage due to key collisions.

A valid cache key must be either an integer number or a non-empty string.

This commit introduces a quick type check on the given cache keys and adds a `_doing_it_wrong()` message that should help plugin developers to notice these issues quicker.

Includes:
* A check in `update_user_caches()` and `clean_user_cache()` to make sure user email is not empty before being cached or removed from cache, as it is technically possible to create a user with empty email via `wp_insert_user()`.
* Some minor cleanup in unit tests where the email was passed to `wp_insert_user()` incorrectly or was unintentionally reset.

Props tillkruess, malthert, dd32, spacedmonkey, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #56198.
Built from https://develop.svn.wordpress.org/trunk@53818


git-svn-id: http://core.svn.wordpress.org/trunk@53377 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-08-03 14:36:12 +00:00
Sergey Biryukov d61b862297 Cache API: Make the placement of `wp_cache_flush_group()` more consistent.
Includes:
* Placing `WP_Object_Cache::flush_group()` next to `::flush()`.
* Placing `wp_cache_supports_group_flush()` next to `wp_cache_flush_group()`.
* Placing the `wp_cache_flush_group()` unit test next to the `::flush()` method test.
* Removing test name from assertion messages, as it is already mentioned directly above in case of failure.
* Adjusting function descriptions per the documentation standards.

Follow-up to [52706], [53763].

See #55647, #4476.
Built from https://develop.svn.wordpress.org/trunk@53767


git-svn-id: http://core.svn.wordpress.org/trunk@53326 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-23 14:58:12 +00:00
spacedmonkey 71cfaa9a5a Cache API: Add `wp_cache_flush_group` function.
Add a new plugable function called `wp_cache_flush_group`, that will allow developers to clear whole cache groups with a single call. Developers can detect if their current implementation of an object cache supports flushing by group, by calling `wp_cache_supports_group_flush` which returns true if it is supported. If the developers of the object cache drop-in has not implemented `wp_cache_flush_group` and `wp_cache_supports_group_flush`, these functions are polyfilled and `wp_cache_supports_group_flush` defaults to false.

Props Spacedmonkey, filosofo, ryan, sc0ttkclark, SergeyBiryukov, scribu, Ste_95, dd32, dhilditch, dougal, lucasbustamante, dg12345, tillkruess, peterwilsoncc, flixos90, pbearne.
Fixes #4476.
Built from https://develop.svn.wordpress.org/trunk@53763


git-svn-id: http://core.svn.wordpress.org/trunk@53322 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-22 20:52:12 +00:00
Sergey Biryukov 11691e8207 Docs: Improve `@return` tags for `wp_cache_*_multiple()` functions:
* `wp_cache_add_multiple()`
* `wp_cache_set_multiple()`
* `wp_cache_get_multiple()`
* `wp_cache_delete_multiple()`

This aims to provide more details about the returned value types.

Follow-up to [52700], [52702], [52703].

See #54729, #54574.
Built from https://develop.svn.wordpress.org/trunk@52708


git-svn-id: http://core.svn.wordpress.org/trunk@52297 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-02-11 19:21:01 +00:00
Sergey Biryukov 6f3fcdcb4b Cache API: Reorder object cache functions and methods for consistency.
The original order was alphabetical, which became less obvious as newer functions got added, resulting in a somewhat random order.

This commits aims to organize the functions and related `WP_Object_Cache` methods in a more predictable order:

* `wp_cache_init()`
* `wp_cache_add()`
* `wp_cache_add_multiple()`
* `wp_cache_replace()`
* `wp_cache_set()`
* `wp_cache_set_multiple()`
* `wp_cache_get()`
* `wp_cache_get_multiple()`
* `wp_cache_delete()`
* `wp_cache_delete_multiple()`
* `wp_cache_incr()`
* `wp_cache_decr()`
* `wp_cache_flush()`
* `wp_cache_close()`
* `wp_cache_add_global_groups()`
* `wp_cache_add_non_persistent_groups()`
* `wp_cache_switch_to_blog()`
* `wp_cache_reset()`

Follow-up to [3011], [6543], [7986], [13066], [18580], [21403], [47938], [52700], [52703-52705].

See #54728, #54574.
Built from https://develop.svn.wordpress.org/trunk@52706


git-svn-id: http://core.svn.wordpress.org/trunk@52295 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-02-11 18:49:03 +00:00
Sergey Biryukov d3f69d117c Docs: Correct the suggested alternative for the deprecated `wp_cache_reset()` function.
While this was previously added and reverted more than once as part of various documentation cleanup efforts, `wp_cache_switch_to_blog()` appears to be the correct alternative for `wp_cache_reset()`, per the latter's DocBlock.

This commit also corrects the `@deprecated` tag for `WP_Object_Cache::reset()` to link to the `::switch_to_blog()` method of the class, instead of the function of the same name.

Follow-up to [13066], [21403], [22111], [33678], [34225], [34226], [40929].

See #54729.
Built from https://develop.svn.wordpress.org/trunk@52705


git-svn-id: http://core.svn.wordpress.org/trunk@52294 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-02-11 18:33:00 +00:00
Sergey Biryukov 7f36a90e0e Docs: Update DocBlocks for some object cache functions per the documentation standards.
Follow-up to [47060], [47938], [47944], [52700].

See #54729, #54574.
Built from https://develop.svn.wordpress.org/trunk@52703


git-svn-id: http://core.svn.wordpress.org/trunk@52292 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-02-11 17:44:01 +00:00
spacedmonkey a3f3c5c959 Cache: Add `wp_cache_*_multiple` functions.
Add new caching functions named `wp_cache_add_multiple`, `wp_cache_set_multiple` and `wp_cache_delete_multiple`. All of these functions allow for an array of data to be passed, so that multiple cache objects can be created / edited / deleted in a single function call. This follows on from [47938] where the `wp_cache_get_multiple` function was introduced and allowed for multiple cache objects to be received in one call. 

Props: spacedmonkey, tillkruess, adamsilverstein, flixos90, mitogh, pbearne. 
Fixes: #54574.

Built from https://develop.svn.wordpress.org/trunk@52700


git-svn-id: http://core.svn.wordpress.org/trunk@52289 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-02-11 12:51:59 +00:00
John Blackbourn 780cdb5eb5 Docs: Various docblock corrections relating to parameter types.
See #51800

Built from https://develop.svn.wordpress.org/trunk@49692


git-svn-id: http://core.svn.wordpress.org/trunk@49415 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-24 21:22:04 +00:00
Sergey Biryukov e13c363b17 Docs: Capitalize "ID", when referring to a post ID, term ID, etc. in a more consistent way.
See #49572.
Built from https://develop.svn.wordpress.org/trunk@48104


git-svn-id: http://core.svn.wordpress.org/trunk@47873 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-20 12:02:12 +00:00
John Blackbourn 37234874a5 Docs: Misc improvements to inline docs.
See #49572.
Built from https://develop.svn.wordpress.org/trunk@48099


git-svn-id: http://core.svn.wordpress.org/trunk@47868 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-19 22:28:13 +00:00
Sergey Biryukov 1d95eb63a7 Docs: Add missing documentation for the `$group` parameter of `WP_Object_Cache::get_multiple()`.
Synchronize documentation between `wp_cache_get_multiple()`, its compat version, and the class method.

See #20875.
Built from https://develop.svn.wordpress.org/trunk@47944


git-svn-id: http://core.svn.wordpress.org/trunk@47717 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-10 09:57:09 +00:00
whyisjake 3e2b649351 Cache API: Introduce `wp_cache_get_multi()`.
Many caching backend have support for multiple gets in a single request. This brings that support to core, with a compatability fallback that will loop over requests if needed.

Fixes: #20875.
Props: nacin, tollmanz, wonderboymusic, ryan, jeremyfelt, spacedmonkey, boonebgorges, dd32, rmccue, ocean90, jipmoors, johnjamesjacoby, tillkruess, donmhico, davidbaumwald, SergeyBiryukov, whyisjake.


Built from https://develop.svn.wordpress.org/trunk@47938


git-svn-id: http://core.svn.wordpress.org/trunk@47711 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-09 19:47:13 +00:00
whyisjake c16fa7c73d Cache API: Ensure proper escaping around the stats method in the cache API.
Props: nickdaugherty, batmoo, whyisjake, westi.

Built from https://develop.svn.wordpress.org/trunk@47637


git-svn-id: http://core.svn.wordpress.org/trunk@47412 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-04-29 15:36:06 +00:00
Sergey Biryukov ecb8633dcc Coding Standards: Move `WP_Object_Cache` to `wp-includes/class-wp-object-cache.php`.
This ensures the file containing the `WP_Object_Cache` class conforms to the coding standards.

For backward compatibility, the new file is included from `wp-includes/cache.php`.

Fixes #49373. See #49222.
Built from https://develop.svn.wordpress.org/trunk@47197


git-svn-id: http://core.svn.wordpress.org/trunk@46997 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-02-06 05:53:06 +00:00