<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[52706] trunk: Cache API: Reorder object cache functions and methods for consistency.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/52706">52706</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/52706","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-02-11 18:47:38 +0000 (Fri, 11 Feb 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/changeset/3011">[3011]</a>, <a href="https://core.trac.wordpress.org/changeset/6543">[6543]</a>, <a href="https://core.trac.wordpress.org/changeset/7986">[7986]</a>, <a href="https://core.trac.wordpress.org/changeset/13066">[13066]</a>, <a href="https://core.trac.wordpress.org/changeset/18580">[18580]</a>, <a href="https://core.trac.wordpress.org/changeset/21403">[21403]</a>, <a href="https://core.trac.wordpress.org/changeset/47938">[47938]</a>, <a href="https://core.trac.wordpress.org/changeset/52700">[52700]</a>, [52703-52705].
See <a href="https://core.trac.wordpress.org/ticket/54728">#54728</a>, <a href="https://core.trac.wordpress.org/ticket/54574">#54574</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescachecompatphp">trunk/src/wp-includes/cache-compat.php</a></li>
<li><a href="#trunksrcwpincludescachephp">trunk/src/wp-includes/cache.php</a></li>
<li><a href="#trunksrcwpincludesclasswpobjectcachephp">trunk/src/wp-includes/class-wp-object-cache.php</a></li>
<li><a href="#trunktestsphpunittestscachephp">trunk/tests/phpunit/tests/cache.php</a></li>
<li><a href="#trunktestsphpunittestspluggablephp">trunk/tests/phpunit/tests/pluggable.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescachecompatphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/cache-compat.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/cache-compat.php 2022-02-11 18:31:48 UTC (rev 52705)
+++ trunk/src/wp-includes/cache-compat.php 2022-02-11 18:47:38 UTC (rev 52706)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -8,28 +8,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @subpackage Cache
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( ! function_exists( 'wp_cache_get_multiple' ) ) :
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( ! function_exists( 'wp_cache_add_multiple' ) ) :
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Retrieves multiple values from the cache in one call.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Adds multiple values to the cache in one call, if the cache keys don't already exist.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Compat function to mimic wp_cache_get_multiple().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Compat function to mimic wp_cache_add_multiple().
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ignore
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.5.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.0.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see wp_cache_get_multiple()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see wp_cache_add_multiple()
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $keys Array of keys under which the cache contents are stored.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @param bool $force Optional. Whether to force an update of the local cache
- * from the persistent cache. Default false.
- * @return array Array of values organized into groups.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $data Array of keys and values to be added.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
+ * @param int $expire Optional. When to expire the cache contents, in seconds.
+ * Default 0 (no expiration).
+ * @return array Array of return values.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function wp_cache_get_multiple( $keys, $group = '', $force = false ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function wp_cache_add_multiple( array $data, $group = '', $expire = 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $values = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $keys as $key ) {
- $values[ $key ] = wp_cache_get( $key, $group, $force );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $data as $key => $value ) {
+ $values[ $key ] = wp_cache_add( $key, $value, $group, $expire );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $values;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -36,26 +36,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> endif;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( ! function_exists( 'wp_cache_delete_multiple' ) ) :
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( ! function_exists( 'wp_cache_set_multiple' ) ) :
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Deletes multiple values from the cache in one call.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Sets multiple values to the cache in one call.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Compat function to mimic wp_cache_delete_multiple().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Differs from wp_cache_add_multiple() in that it will always write data.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Compat function to mimic wp_cache_set_multiple().
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ignore
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see wp_cache_delete_multiple()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see wp_cache_set_multiple()
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $keys Array of keys under which the cache to deleted.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $data Array of keys and values to be set.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
+ * @param int $expire Optional. When to expire the cache contents, in seconds.
+ * Default 0 (no expiration).
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array Array of return values.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function wp_cache_delete_multiple( array $keys, $group = '' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function wp_cache_set_multiple( array $data, $group = '', $expire = 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $values = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $keys as $key ) {
- $values[ $key ] = wp_cache_delete( $key, $group );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $data as $key => $value ) {
+ $values[ $key ] = wp_cache_set( $key, $value, $group, $expire );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $values;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -62,29 +66,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> endif;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-if ( ! function_exists( 'wp_cache_add_multiple' ) ) :
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( ! function_exists( 'wp_cache_get_multiple' ) ) :
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Adds multiple values to the cache in one call, if the cache keys don't already exist.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Retrieves multiple values from the cache in one call.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Compat function to mimic wp_cache_add_multiple().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Compat function to mimic wp_cache_get_multiple().
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ignore
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 6.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.5.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see wp_cache_add_multiple()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see wp_cache_get_multiple()
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $data Array of keys and values to be added.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @param int $expire Optional. When to expire the cache contents, in seconds.
- * Default 0 (no expiration).
- * @return array Array of return values.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $keys Array of keys under which the cache contents are stored.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
+ * @param bool $force Optional. Whether to force an update of the local cache
+ * from the persistent cache. Default false.
+ * @return array Array of values organized into groups.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function wp_cache_add_multiple( array $data, $group = '', $expire = 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function wp_cache_get_multiple( $keys, $group = '', $force = false ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $values = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $data as $key => $value ) {
- $values[ $key ] = wp_cache_add( $key, $value, $group, $expire );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $keys as $key ) {
+ $values[ $key ] = wp_cache_get( $key, $group, $force );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $values;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -91,30 +94,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> endif;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( ! function_exists( 'wp_cache_set_multiple' ) ) :
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( ! function_exists( 'wp_cache_delete_multiple' ) ) :
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Sets multiple values to the cache in one call.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Deletes multiple values from the cache in one call.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Differs from wp_cache_add_multiple() in that it will always write data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Compat function to mimic wp_cache_delete_multiple().
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Compat function to mimic wp_cache_set_multiple().
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @ignore
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see wp_cache_set_multiple()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see wp_cache_delete_multiple()
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $data Array of keys and values to be set.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @param int $expire Optional. When to expire the cache contents, in seconds.
- * Default 0 (no expiration).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $keys Array of keys under which the cache to deleted.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array Array of return values.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function wp_cache_set_multiple( array $data, $group = '', $expire = 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function wp_cache_delete_multiple( array $keys, $group = '' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $values = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $data as $key => $value ) {
- $values[ $key ] = wp_cache_set( $key, $value, $group, $expire );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $keys as $key ) {
+ $values[ $key ] = wp_cache_delete( $key, $group );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $values;
</span></span></pre></div>
<a id="trunksrcwpincludescachephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/cache.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/cache.php 2022-02-11 18:31:48 UTC (rev 52705)
+++ trunk/src/wp-includes/cache.php 2022-02-11 18:47:38 UTC (rev 52706)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -12,6 +12,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . WPINC . '/class-wp-object-cache.php';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Sets up Object Cache Global and assigns it.
+ *
+ * @since 2.0.0
+ *
+ * @global WP_Object_Cache $wp_object_cache
+ */
+function wp_cache_init() {
+ $GLOBALS['wp_object_cache'] = new WP_Object_Cache();
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Adds data to the cache, if the cache key doesn't already exist.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -34,74 +45,89 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Closes the cache.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Adds multiple values to the cache in one call.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * This function has ceased to do anything since WordPress 2.5. The
- * functionality was removed along with the rest of the persistent cache.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.0.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * This does not mean that plugins can't implement this function when they need
- * to make sure that the cache is cleaned up after WordPress no longer needs it.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Object_Cache::add_multiple()
+ * @global WP_Object_Cache $wp_object_cache Object cache global instance.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.0.0
- *
- * @return true Always returns true.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $data Array of keys and values to be set.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
+ * @param int $expire Optional. When to expire the cache contents, in seconds.
+ * Default 0 (no expiration).
+ * @return array Array of return values.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_cache_close() {
- return true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_cache_add_multiple( array $data, $group = '', $expire = 0 ) {
+ global $wp_object_cache;
+
+ return $wp_object_cache->add_multiple( $data, $group, $expire );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Decrements numeric cache item's value.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Replaces the contents of the cache with new data.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 3.3.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.0.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see WP_Object_Cache::decr()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Object_Cache::replace()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Object_Cache $wp_object_cache Object cache global instance.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int|string $key The cache key to decrement.
- * @param int $offset Optional. The amount by which to decrement the item's value.
- * Default 1.
- * @param string $group Optional. The group the key is in. Default empty.
- * @return int|false The item's new value on success, false on failure.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int|string $key The key for the cache data that should be replaced.
+ * @param mixed $data The new data to store in the cache.
+ * @param string $group Optional. The group for the cache data that should be replaced.
+ * Default empty.
+ * @param int $expire Optional. When to expire the cache contents, in seconds.
+ * Default 0 (no expiration).
+ * @return bool True if contents were replaced, false if original value does not exist.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_cache_decr( $key, $offset = 1, $group = '' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_object_cache;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wp_object_cache->decr( $key, $offset, $group );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wp_object_cache->replace( $key, $data, $group, (int) $expire );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Removes the cache contents matching key and group.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Saves the data to the cache.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see WP_Object_Cache::delete()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Object_Cache::set()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Object_Cache $wp_object_cache Object cache global instance.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int|string $key What the contents in the cache are called.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @return bool True on successful removal, false on failure.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int|string $key The cache key to use for retrieval later.
+ * @param mixed $data The contents to store in the cache.
+ * @param string $group Optional. Where to group the cache contents. Enables the same key
+ * to be used across groups. Default empty.
+ * @param int $expire Optional. When to expire the cache contents, in seconds.
+ * Default 0 (no expiration).
+ * @return bool True on success, false on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_cache_delete( $key, $group = '' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_object_cache;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wp_object_cache->delete( $key, $group );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wp_object_cache->set( $key, $data, $group, (int) $expire );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Removes all cache items.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Sets multiple values to the cache in one call.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.0.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see WP_Object_Cache::flush()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Object_Cache::set_multiple()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Object_Cache $wp_object_cache Object cache global instance.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool True on success, false on failure.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $data Array of keys and values to be set.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
+ * @param int $expire Optional. When to expire the cache contents, in seconds.
+ * Default 0 (no expiration).
+ * @return array Array of return values.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_cache_flush() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_cache_set_multiple( array $data, $group = '', $expire = 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_object_cache;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wp_object_cache->flush();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wp_object_cache->set_multiple( $data, $group, $expire );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -147,64 +173,42 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Deletes multiple values from the cache in one call.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Removes the cache contents matching key and group.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 6.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.0.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see WP_Object_Cache::delete_multiple()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Object_Cache::delete()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Object_Cache $wp_object_cache Object cache global instance.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $keys Array of keys under which the cache to deleted.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @return array Array of return values.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int|string $key What the contents in the cache are called.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
+ * @return bool True on successful removal, false on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_cache_delete_multiple( array $keys, $group = '' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_cache_delete( $key, $group = '' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_object_cache;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wp_object_cache->delete_multiple( $keys, $group );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wp_object_cache->delete( $key, $group );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Adds multiple values to the cache in one call.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Deletes multiple values from the cache in one call.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see WP_Object_Cache::add_multiple()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Object_Cache::delete_multiple()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Object_Cache $wp_object_cache Object cache global instance.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $data Array of keys and values to be set.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @param int $expire Optional. When to expire the cache contents, in seconds.
- * Default 0 (no expiration).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $keys Array of keys under which the cache to deleted.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array Array of return values.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_cache_add_multiple( array $data, $group = '', $expire = 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_cache_delete_multiple( array $keys, $group = '' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_object_cache;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wp_object_cache->add_multiple( $data, $group, $expire );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wp_object_cache->delete_multiple( $keys, $group );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Sets multiple values to the cache in one call.
- *
- * @since 6.0.0
- *
- * @see WP_Object_Cache::set_multiple()
- * @global WP_Object_Cache $wp_object_cache Object cache global instance.
- *
- * @param array $data Array of keys and values to be set.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @param int $expire Optional. When to expire the cache contents, in seconds.
- * Default 0 (no expiration).
- * @return array Array of return values.
- */
-function wp_cache_set_multiple( array $data, $group = '', $expire = 0 ) {
- global $wp_object_cache;
-
- return $wp_object_cache->set_multiple( $data, $group, $expire );
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * Increments numeric cache item's value.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.3.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -225,78 +229,56 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Sets up Object Cache Global and assigns it.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Decrements numeric cache item's value.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 3.3.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @global WP_Object_Cache $wp_object_cache
- */
-function wp_cache_init() {
- $GLOBALS['wp_object_cache'] = new WP_Object_Cache();
-}
-
-/**
- * Replaces the contents of the cache with new data.
- *
- * @since 2.0.0
- *
- * @see WP_Object_Cache::replace()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Object_Cache::decr()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Object_Cache $wp_object_cache Object cache global instance.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int|string $key The key for the cache data that should be replaced.
- * @param mixed $data The new data to store in the cache.
- * @param string $group Optional. The group for the cache data that should be replaced.
- * Default empty.
- * @param int $expire Optional. When to expire the cache contents, in seconds.
- * Default 0 (no expiration).
- * @return bool True if contents were replaced, false if original value does not exist.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int|string $key The cache key to decrement.
+ * @param int $offset Optional. The amount by which to decrement the item's value.
+ * Default 1.
+ * @param string $group Optional. The group the key is in. Default empty.
+ * @return int|false The item's new value on success, false on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_cache_decr( $key, $offset = 1, $group = '' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_object_cache;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wp_object_cache->replace( $key, $data, $group, (int) $expire );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wp_object_cache->decr( $key, $offset, $group );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Saves the data to the cache.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Removes all cache items.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see WP_Object_Cache::set()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Object_Cache::flush()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @global WP_Object_Cache $wp_object_cache Object cache global instance.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int|string $key The cache key to use for retrieval later.
- * @param mixed $data The contents to store in the cache.
- * @param string $group Optional. Where to group the cache contents. Enables the same key
- * to be used across groups. Default empty.
- * @param int $expire Optional. When to expire the cache contents, in seconds.
- * Default 0 (no expiration).
</del><span class="cx" style="display: block; padding: 0 10px"> * @return bool True on success, false on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_cache_flush() {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_object_cache;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $wp_object_cache->set( $key, $data, $group, (int) $expire );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wp_object_cache->flush();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Switches the internal blog ID.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Closes the cache.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * This changes the blog id used to create keys in blog specific groups.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * This function has ceased to do anything since WordPress 2.5. The
+ * functionality was removed along with the rest of the persistent cache.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 3.5.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * This does not mean that plugins can't implement this function when they need
+ * to make sure that the cache is cleaned up after WordPress no longer needs it.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see WP_Object_Cache::switch_to_blog()
- * @global WP_Object_Cache $wp_object_cache Object cache global instance.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.0.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $blog_id Site ID.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return true Always returns true.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_cache_switch_to_blog( $blog_id ) {
- global $wp_object_cache;
-
- $wp_object_cache->switch_to_blog( $blog_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_cache_close() {
+ return true;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -327,8 +309,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Reset internal cache keys and structures.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Switches the internal blog ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * This changes the blog id used to create keys in blog specific groups.
+ *
+ * @since 3.5.0
+ *
+ * @see WP_Object_Cache::switch_to_blog()
+ * @global WP_Object_Cache $wp_object_cache Object cache global instance.
+ *
+ * @param int $blog_id Site ID.
+ */
+function wp_cache_switch_to_blog( $blog_id ) {
+ global $wp_object_cache;
+
+ $wp_object_cache->switch_to_blog( $blog_id );
+}
+
+/**
+ * Resets internal cache keys and structures.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * If the cache back end uses global blog or site IDs as part of its cache keys,
</span><span class="cx" style="display: block; padding: 0 10px"> * this function instructs the back end to reset those keys and perform any cleanup
</span><span class="cx" style="display: block; padding: 0 10px"> * since blog or site IDs have changed since cache init.
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpobjectcachephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-object-cache.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-object-cache.php 2022-02-11 18:31:48 UTC (rev 52705)
+++ trunk/src/wp-includes/class-wp-object-cache.php 2022-02-11 18:47:38 UTC (rev 52706)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -130,6 +130,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Serves as a utility function to determine whether a key exists in the cache.
+ *
+ * @since 3.4.0
+ *
+ * @param int|string $key Cache key to check for existence.
+ * @param string $group Cache group for the key existence check.
+ * @return bool Whether the key exists in the cache for the given group.
+ */
+ protected function _exists( $key, $group ) {
+ return isset( $this->cache[ $group ] ) && ( isset( $this->cache[ $group ][ $key ] ) || array_key_exists( $key, $this->cache[ $group ] ) );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Adds data to the cache if it doesn't already exist.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -167,71 +180,78 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Sets the list of global cache groups.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Adds multiple values to the cache in one call.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 3.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.0.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string|string[] $groups List of groups that are global.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $data Array of keys and values to be added.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
+ * @param int $expire Optional. When to expire the cache contents, in seconds.
+ * Default 0 (no expiration).
+ * @return array Array of return values.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function add_global_groups( $groups ) {
- $groups = (array) $groups;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function add_multiple( array $data, $group = '', $expire = 0 ) {
+ $values = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $groups = array_fill_keys( $groups, true );
- $this->global_groups = array_merge( $this->global_groups, $groups );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $data as $key => $value ) {
+ $values[ $key ] = $this->add( $key, $value, $group, $expire );
+ }
+
+ return $values;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Decrements numeric cache item's value.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Replaces the contents in the cache, if contents already exist.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 3.3.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.0.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int|string $key The cache key to decrement.
- * @param int $offset Optional. The amount by which to decrement the item's value.
- * Default 1.
- * @param string $group Optional. The group the key is in. Default 'default'.
- * @return int|false The item's new value on success, false on failure.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Object_Cache::set()
+ *
+ * @param int|string $key What to call the contents in the cache.
+ * @param mixed $data The contents to store in the cache.
+ * @param string $group Optional. Where to group the cache contents. Default 'default'.
+ * @param int $expire Optional. When to expire the cache contents, in seconds.
+ * Default 0 (no expiration).
+ * @return bool True if contents were replaced, false if original value does not exist.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function decr( $key, $offset = 1, $group = 'default' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function replace( $key, $data, $group = 'default', $expire = 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $group ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $group = 'default';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $id = $key;
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $key = $this->blog_prefix . $key;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $id = $this->blog_prefix . $key;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $this->_exists( $key, $group ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $this->_exists( $id, $group ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) {
- $this->cache[ $group ][ $key ] = 0;
- }
-
- $offset = (int) $offset;
-
- $this->cache[ $group ][ $key ] -= $offset;
-
- if ( $this->cache[ $group ][ $key ] < 0 ) {
- $this->cache[ $group ][ $key ] = 0;
- }
-
- return $this->cache[ $group ][ $key ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $this->set( $key, $data, $group, (int) $expire );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Removes the contents of the cache key in the group.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Sets the data contents into the cache.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * If the cache key does not exist in the group, then nothing will happen.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The cache contents are grouped by the $group parameter followed by the
+ * $key. This allows for duplicate IDs in unique groups. Therefore, naming of
+ * the group should be used with care and should follow normal function
+ * naming guidelines outside of core WordPress usage.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The $expire parameter is not used, because the cache will automatically
+ * expire for each time a page is accessed and PHP finishes. The method is
+ * more for cache plugins which use files.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int|string $key What the contents in the cache are called.
- * @param string $group Optional. Where the cache contents are grouped. Default 'default'.
- * @param bool $deprecated Optional. Unused. Default false.
- * @return bool True on success, false if the contents were not deleted.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int|string $key What to call the contents in the cache.
+ * @param mixed $data The contents to store in the cache.
+ * @param string $group Optional. Where to group the cache contents. Default 'default'.
+ * @param int $expire Optional. Not used.
+ * @return true Always returns true.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function delete( $key, $group = 'default', $deprecated = false ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function set( $key, $data, $group = 'default', $expire = 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $group ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $group = 'default';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -240,25 +260,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $key = $this->blog_prefix . $key;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $this->_exists( $key, $group ) ) {
- return false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_object( $data ) ) {
+ $data = clone $data;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unset( $this->cache[ $group ][ $key ] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->cache[ $group ][ $key ] = $data;
</ins><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Clears the object cache of all data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Sets multiple values to the cache in one call.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.0.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return true Always returns true.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $data Array of key and value to be set.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
+ * @param int $expire Optional. When to expire the cache contents, in seconds.
+ * Default 0 (no expiration).
+ * @return array Array of return values.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function flush() {
- $this->cache = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function set_multiple( array $data, $group = '', $expire = 0 ) {
+ $values = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $data as $key => $value ) {
+ $values[ $key ] = $this->set( $key, $value, $group, $expire );
+ }
+
+ return $values;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -326,61 +354,48 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Deletes multiple values from the cache in one call.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Removes the contents of the cache key in the group.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 6.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * If the cache key does not exist in the group, then nothing will happen.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $keys Array of keys to be deleted.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @return array Array of return values.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.0.0
+ *
+ * @param int|string $key What the contents in the cache are called.
+ * @param string $group Optional. Where the cache contents are grouped. Default 'default'.
+ * @param bool $deprecated Optional. Unused. Default false.
+ * @return bool True on success, false if the contents were not deleted.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function delete_multiple( array $keys, $group = '' ) {
- $values = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function delete( $key, $group = 'default', $deprecated = false ) {
+ if ( empty( $group ) ) {
+ $group = 'default';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $keys as $key ) {
- $values[ $key ] = $this->delete( $key, $group );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
+ $key = $this->blog_prefix . $key;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $values;
- }
-
- /**
- * Adds multiple values to the cache in one call.
- *
- * @since 6.0.0
- *
- * @param array $data Array of keys and values to be added.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @param int $expire Optional. When to expire the cache contents, in seconds.
- * Default 0 (no expiration).
- * @return array Array of return values.
- */
- public function add_multiple( array $data, $group = '', $expire = 0 ) {
- $values = array();
-
- foreach ( $data as $key => $value ) {
- $values[ $key ] = $this->add( $key, $value, $group, $expire );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $this->_exists( $key, $group ) ) {
+ return false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $values;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unset( $this->cache[ $group ][ $key ] );
+ return true;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Sets multiple values to the cache in one call.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Deletes multiple values from the cache in one call.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $data Array of key and value to be set.
- * @param string $group Optional. Where the cache contents are grouped. Default empty.
- * @param int $expire Optional. When to expire the cache contents, in seconds.
- * Default 0 (no expiration).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $keys Array of keys to be deleted.
+ * @param string $group Optional. Where the cache contents are grouped. Default empty.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array Array of return values.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function set_multiple( array $data, $group = '', $expire = 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function delete_multiple( array $keys, $group = '' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $values = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $data as $key => $value ) {
- $values[ $key ] = $this->set( $key, $value, $group, $expire );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $keys as $key ) {
+ $values[ $key ] = $this->delete( $key, $group );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $values;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -426,37 +441,86 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Replaces the contents in the cache, if contents already exist.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Decrements numeric cache item's value.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 3.3.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @see WP_Object_Cache::set()
- *
- * @param int|string $key What to call the contents in the cache.
- * @param mixed $data The contents to store in the cache.
- * @param string $group Optional. Where to group the cache contents. Default 'default'.
- * @param int $expire Optional. When to expire the cache contents, in seconds.
- * Default 0 (no expiration).
- * @return bool True if contents were replaced, false if original value does not exist.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int|string $key The cache key to decrement.
+ * @param int $offset Optional. The amount by which to decrement the item's value.
+ * Default 1.
+ * @param string $group Optional. The group the key is in. Default 'default'.
+ * @return int|false The item's new value on success, false on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function replace( $key, $data, $group = 'default', $expire = 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function decr( $key, $offset = 1, $group = 'default' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $group ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $group = 'default';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $id = $key;
</del><span class="cx" style="display: block; padding: 0 10px"> if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $id = $this->blog_prefix . $key;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $key = $this->blog_prefix . $key;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $this->_exists( $id, $group ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $this->_exists( $key, $group ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $this->set( $key, $data, $group, (int) $expire );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) {
+ $this->cache[ $group ][ $key ] = 0;
+ }
+
+ $offset = (int) $offset;
+
+ $this->cache[ $group ][ $key ] -= $offset;
+
+ if ( $this->cache[ $group ][ $key ] < 0 ) {
+ $this->cache[ $group ][ $key ] = 0;
+ }
+
+ return $this->cache[ $group ][ $key ];
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Clears the object cache of all data.
+ *
+ * @since 2.0.0
+ *
+ * @return true Always returns true.
+ */
+ public function flush() {
+ $this->cache = array();
+
+ return true;
+ }
+
+ /**
+ * Sets the list of global cache groups.
+ *
+ * @since 3.0.0
+ *
+ * @param string|string[] $groups List of groups that are global.
+ */
+ public function add_global_groups( $groups ) {
+ $groups = (array) $groups;
+
+ $groups = array_fill_keys( $groups, true );
+ $this->global_groups = array_merge( $this->global_groups, $groups );
+ }
+
+ /**
+ * Switches the internal blog ID.
+ *
+ * This changes the blog ID used to create keys in blog specific groups.
+ *
+ * @since 3.5.0
+ *
+ * @param int $blog_id Blog ID.
+ */
+ public function switch_to_blog( $blog_id ) {
+ $blog_id = (int) $blog_id;
+ $this->blog_prefix = $this->multisite ? $blog_id . ':' : '';
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Resets cache keys.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -476,43 +540,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Sets the data contents into the cache.
- *
- * The cache contents are grouped by the $group parameter followed by the
- * $key. This allows for duplicate IDs in unique groups. Therefore, naming of
- * the group should be used with care and should follow normal function
- * naming guidelines outside of core WordPress usage.
- *
- * The $expire parameter is not used, because the cache will automatically
- * expire for each time a page is accessed and PHP finishes. The method is
- * more for cache plugins which use files.
- *
- * @since 2.0.0
- *
- * @param int|string $key What to call the contents in the cache.
- * @param mixed $data The contents to store in the cache.
- * @param string $group Optional. Where to group the cache contents. Default 'default'.
- * @param int $expire Optional. Not used.
- * @return true Always returns true.
- */
- public function set( $key, $data, $group = 'default', $expire = 0 ) {
- if ( empty( $group ) ) {
- $group = 'default';
- }
-
- if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
- $key = $this->blog_prefix . $key;
- }
-
- if ( is_object( $data ) ) {
- $data = clone $data;
- }
-
- $this->cache[ $group ][ $key ] = $data;
- return true;
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * Echoes the stats of the caching.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Gives the cache hits, and cache misses. Also prints every cached group,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -531,31 +558,4 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> echo '</ul>';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- /**
- * Switches the internal blog ID.
- *
- * This changes the blog ID used to create keys in blog specific groups.
- *
- * @since 3.5.0
- *
- * @param int $blog_id Blog ID.
- */
- public function switch_to_blog( $blog_id ) {
- $blog_id = (int) $blog_id;
- $this->blog_prefix = $this->multisite ? $blog_id . ':' : '';
- }
-
- /**
- * Serves as a utility function to determine whether a key exists in the cache.
- *
- * @since 3.4.0
- *
- * @param int|string $key Cache key to check for existence.
- * @param string $group Cache group for the key existence check.
- * @return bool Whether the key exists in the cache for the given group.
- */
- protected function _exists( $key, $group ) {
- return isset( $this->cache[ $group ] ) && ( isset( $this->cache[ $group ][ $key ] ) || array_key_exists( $key, $this->cache[ $group ] ) );
- }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestscachephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/cache.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/cache.php 2022-02-11 18:31:48 UTC (rev 52705)
+++ trunk/tests/phpunit/tests/cache.php 2022-02-11 18:47:38 UTC (rev 52706)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -332,25 +332,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @ticket 20875
- */
- public function test_get_multiple() {
- wp_cache_set( 'foo1', 'bar', 'group1' );
- wp_cache_set( 'foo2', 'bar', 'group1' );
- wp_cache_set( 'foo1', 'bar', 'group2' );
-
- $found = wp_cache_get_multiple( array( 'foo1', 'foo2', 'foo3' ), 'group1' );
-
- $expected = array(
- 'foo1' => 'bar',
- 'foo2' => 'bar',
- 'foo3' => false,
- );
-
- $this->assertSame( $expected, $found );
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * @ticket 54574
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_cache_add_multiple() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -395,6 +376,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 20875
+ */
+ public function test_wp_cache_get_multiple() {
+ wp_cache_set( 'foo1', 'bar', 'group1' );
+ wp_cache_set( 'foo2', 'bar', 'group1' );
+ wp_cache_set( 'foo1', 'bar', 'group2' );
+
+ $found = wp_cache_get_multiple( array( 'foo1', 'foo2', 'foo3' ), 'group1' );
+
+ $expected = array(
+ 'foo1' => 'bar',
+ 'foo2' => 'bar',
+ 'foo3' => false,
+ );
+
+ $this->assertSame( $expected, $found );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 54574
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_cache_delete_multiple() {
</span></span></pre></div>
<a id="trunktestsphpunittestspluggablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/pluggable.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/pluggable.php 2022-02-11 18:31:48 UTC (rev 52705)
+++ trunk/tests/phpunit/tests/pluggable.php 2022-02-11 18:47:38 UTC (rev 52706)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -267,6 +267,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // wp-includes/cache.php:
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp_cache_init' => array(),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'wp_cache_add' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'key',
</span><span class="cx" style="display: block; padding: 0 10px"> 'data',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -273,17 +274,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'group' => '',
</span><span class="cx" style="display: block; padding: 0 10px"> 'expire' => 0,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wp_cache_close' => array(),
- 'wp_cache_decr' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp_cache_add_multiple' => array(
+ 'data',
+ 'group' => '',
+ 'expire' => 0,
+ ),
+ 'wp_cache_replace' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'key',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'offset' => 1,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'data',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'group' => '',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'expire' => 0,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wp_cache_delete' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp_cache_set' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'key',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'group' => '',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'data',
+ 'group' => '',
+ 'expire' => 0,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wp_cache_flush' => array(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp_cache_set_multiple' => array(
+ 'data',
+ 'group' => '',
+ 'expire' => 0,
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'wp_cache_get' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'key',
</span><span class="cx" style="display: block; padding: 0 10px"> 'group' => '',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -295,16 +307,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'group' => '',
</span><span class="cx" style="display: block; padding: 0 10px"> 'force' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wp_cache_set_multiple' => array(
- 'data',
- 'group' => '',
- 'expire' => 0,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp_cache_delete' => array(
+ 'key',
+ 'group' => '',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wp_cache_add_multiple' => array(
- 'data',
- 'group' => '',
- 'expire' => 0,
- ),
</del><span class="cx" style="display: block; padding: 0 10px"> 'wp_cache_delete_multiple' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'keys',
</span><span class="cx" style="display: block; padding: 0 10px"> 'group' => '',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -314,22 +320,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'offset' => 1,
</span><span class="cx" style="display: block; padding: 0 10px"> 'group' => '',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wp_cache_init' => array(),
- 'wp_cache_replace' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp_cache_decr' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'key',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'data',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'offset' => 1,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'group' => '',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'expire' => 0,
</del><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wp_cache_set' => array(
- 'key',
- 'data',
- 'group' => '',
- 'expire' => 0,
- ),
- 'wp_cache_switch_to_blog' => array( 'blog_id' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp_cache_flush' => array(),
+ 'wp_cache_close' => array(),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'wp_cache_add_global_groups' => array( 'groups' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp_cache_add_non_persistent_groups' => array( 'groups' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp_cache_switch_to_blog' => array( 'blog_id' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'wp_cache_reset' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span></span></pre>
</div>
</div>
</body>
</html>