diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/cache.php --- a/wp/wp-includes/cache.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/cache.php Mon Oct 14 18:28:13 2019 +0200 @@ -81,7 +81,7 @@ function wp_cache_delete( $key, $group = '' ) { global $wp_object_cache; - return $wp_object_cache->delete($key, $group); + return $wp_object_cache->delete( $key, $group ); } /** @@ -115,7 +115,7 @@ * @param bool $found Optional. Whether the key was found in the cache (passed by reference). * Disambiguates a return of false, a storable value. Default null. * @return bool|mixed False on failure to retrieve contents or the cache - * contents on success + * contents on success */ function wp_cache_get( $key, $group = '', $force = false, &$found = null ) { global $wp_object_cache; @@ -323,7 +323,7 @@ * The blog prefix to prepend to keys in non-global groups. * * @since 3.5.0 - * @var int + * @var string */ private $blog_prefix; @@ -390,7 +390,7 @@ * * @uses WP_Object_Cache::_exists() Checks to see if the cache already has data. * @uses WP_Object_Cache::set() Sets the data after the checking the cache - * contents existence. + * contents existence. * * @param int|string $key What to call the contents in the cache. * @param mixed $data The contents to store in the cache. @@ -399,18 +399,22 @@ * @return bool False if cache key and group already exist, true on success */ public function add( $key, $data, $group = 'default', $expire = 0 ) { - if ( wp_suspend_cache_addition() ) + if ( wp_suspend_cache_addition() ) { return false; + } - if ( empty( $group ) ) + if ( empty( $group ) ) { $group = 'default'; + } $id = $key; - if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) + if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) { $id = $this->blog_prefix . $key; + } - if ( $this->_exists( $id, $group ) ) + if ( $this->_exists( $id, $group ) ) { return false; + } return $this->set( $key, $data, $group, (int) $expire ); } @@ -425,7 +429,7 @@ public function add_global_groups( $groups ) { $groups = (array) $groups; - $groups = array_fill_keys( $groups, true ); + $groups = array_fill_keys( $groups, true ); $this->global_groups = array_merge( $this->global_groups, $groups ); } @@ -440,24 +444,29 @@ * @return false|int False on failure, the item's new value on success. */ public function decr( $key, $offset = 1, $group = 'default' ) { - if ( empty( $group ) ) + if ( empty( $group ) ) { $group = 'default'; + } - if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) + if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) { $key = $this->blog_prefix . $key; + } - if ( ! $this->_exists( $key, $group ) ) + if ( ! $this->_exists( $key, $group ) ) { return false; + } - if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) + 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 ) + if ( $this->cache[ $group ][ $key ] < 0 ) { $this->cache[ $group ][ $key ] = 0; + } return $this->cache[ $group ][ $key ]; } @@ -475,16 +484,19 @@ * @return bool False if the contents weren't deleted and true on success. */ public function delete( $key, $group = 'default', $deprecated = false ) { - if ( empty( $group ) ) + if ( empty( $group ) ) { $group = 'default'; + } - if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) + if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) { $key = $this->blog_prefix . $key; + } - if ( ! $this->_exists( $key, $group ) ) + if ( ! $this->_exists( $key, $group ) ) { return false; + } - unset( $this->cache[$group][$key] ); + unset( $this->cache[ $group ][ $key ] ); return true; } @@ -514,29 +526,32 @@ * * @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 string $force Optional. Unused. Whether to force a refetch rather than relying on the local + * @param bool $force Optional. Unused. Whether to force a refetch rather than relying on the local * cache. Default false. - * @param bool $found Optional. Whether the key was found in the cache (passed by reference). - * Disambiguates a return of false, a storable value. Default null. + * @param bool $found Optional. Whether the key was found in the cache (passed by reference). + * Disambiguates a return of false, a storable value. Default null. * @return false|mixed False on failure to retrieve contents or the cache contents on success. */ public function get( $key, $group = 'default', $force = false, &$found = null ) { - if ( empty( $group ) ) + if ( empty( $group ) ) { $group = 'default'; + } - if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) + if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) { $key = $this->blog_prefix . $key; + } if ( $this->_exists( $key, $group ) ) { - $found = true; + $found = true; $this->cache_hits += 1; - if ( is_object($this->cache[$group][$key]) ) - return clone $this->cache[$group][$key]; - else - return $this->cache[$group][$key]; + if ( is_object( $this->cache[ $group ][ $key ] ) ) { + return clone $this->cache[ $group ][ $key ]; + } else { + return $this->cache[ $group ][ $key ]; + } } - $found = false; + $found = false; $this->cache_misses += 1; return false; } @@ -552,24 +567,29 @@ * @return false|int False on failure, the item's new value on success. */ public function incr( $key, $offset = 1, $group = 'default' ) { - if ( empty( $group ) ) + if ( empty( $group ) ) { $group = 'default'; + } - if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) + if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) { $key = $this->blog_prefix . $key; + } - if ( ! $this->_exists( $key, $group ) ) + if ( ! $this->_exists( $key, $group ) ) { return false; + } - if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) + 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 ) + if ( $this->cache[ $group ][ $key ] < 0 ) { $this->cache[ $group ][ $key ] = 0; + } return $this->cache[ $group ][ $key ]; } @@ -588,15 +608,18 @@ * @return bool False if not exists, true if contents were replaced. */ public function replace( $key, $data, $group = 'default', $expire = 0 ) { - if ( empty( $group ) ) + if ( empty( $group ) ) { $group = 'default'; + } $id = $key; - if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) + if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) { $id = $this->blog_prefix . $key; + } - if ( ! $this->_exists( $id, $group ) ) + if ( ! $this->_exists( $id, $group ) ) { return false; + } return $this->set( $key, $data, $group, (int) $expire ); } @@ -614,15 +637,16 @@ // Clear out non-global caches since the blog ID has changed. foreach ( array_keys( $this->cache ) as $group ) { - if ( ! isset( $this->global_groups[ $group ] ) ) + if ( ! isset( $this->global_groups[ $group ] ) ) { unset( $this->cache[ $group ] ); + } } } /** * Sets the data contents into the cache. * - * The cache contents is grouped by the $group parameter followed by the + * 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. @@ -640,16 +664,19 @@ * @return true Always returns true. */ public function set( $key, $data, $group = 'default', $expire = 0 ) { - if ( empty( $group ) ) + if ( empty( $group ) ) { $group = 'default'; + } - if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) + if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) { $key = $this->blog_prefix . $key; + } - if ( is_object( $data ) ) + if ( is_object( $data ) ) { $data = clone $data; + } - $this->cache[$group][$key] = $data; + $this->cache[ $group ][ $key ] = $data; return true; } @@ -662,12 +689,12 @@ * @since 2.0.0 */ public function stats() { - echo "

"; + echo '

'; echo "Cache Hits: {$this->cache_hits}
"; echo "Cache Misses: {$this->cache_misses}
"; - echo "

"; + echo '

'; echo ''; @@ -683,7 +710,7 @@ * @param int $blog_id Blog ID. */ public function switch_to_blog( $blog_id ) { - $blog_id = (int) $blog_id; + $blog_id = (int) $blog_id; $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; } @@ -706,9 +733,8 @@ * @since 2.0.8 */ public function __construct() { - $this->multisite = is_multisite(); - $this->blog_prefix = $this->multisite ? get_current_blog_id() . ':' : ''; - + $this->multisite = is_multisite(); + $this->blog_prefix = $this->multisite ? get_current_blog_id() . ':' : ''; /** * @todo This should be moved to the PHP4 style constructor, PHP5