Changeset 45607 for trunk/tests/phpunit/includes/object-cache.php
- Timestamp:
- 07/08/2019 12:55:20 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/object-cache.php
r45580 r45607 873 873 * @param int $expiration The expiration time, defaults to 0. 874 874 * @param string $server_key The key identifying the server to store the value on. 875 * @param bool $by KeyTrue to store in internal cache by key; false to not store by key875 * @param bool $by_key True to store in internal cache by key; false to not store by key 876 876 * @return bool Returns TRUE on success or FALSE on failure. 877 877 */ 878 public function add( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by Key = false ) {878 public function add( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { 879 879 /* 880 880 * Ensuring that wp_suspend_cache_addition is defined before calling, because sometimes an advanced-cache.php … … 891 891 892 892 // If group is a non-Memcached group, save to runtime cache, not Memcached 893 if ( in_array( $group, $this->no_mc_groups ) ) {893 if ( in_array( $group, $this->no_mc_groups, true ) ) { 894 894 895 895 // Add does not set the value if the key exists; mimic that here … … 904 904 905 905 // Save to Memcached 906 if ( $by Key ) {906 if ( $by_key ) { 907 907 $result = $this->m->addByKey( $server_key, $derived_key, $value, $expiration ); 908 908 } else { … … 992 992 * @param string $group The group value appended to the $key. 993 993 * @param string $server_key The key identifying the server to store the value on. 994 * @param bool $by KeyTrue to store in internal cache by key; false to not store by key994 * @param bool $by_key True to store in internal cache by key; false to not store by key 995 995 * @return bool Returns TRUE on success or FALSE on failure. 996 996 */ 997 public function append( $key, $value, $group = 'default', $server_key = '', $by Key = false ) {997 public function append( $key, $value, $group = 'default', $server_key = '', $by_key = false ) { 998 998 if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) ) { 999 999 return false; … … 1003 1003 1004 1004 // If group is a non-Memcached group, append to runtime cache value, not Memcached 1005 if ( in_array( $group, $this->no_mc_groups ) ) {1005 if ( in_array( $group, $this->no_mc_groups, true ) ) { 1006 1006 if ( ! isset( $this->cache[ $derived_key ] ) ) { 1007 1007 return false; … … 1014 1014 1015 1015 // Append to Memcached value 1016 if ( $by Key ) {1016 if ( $by_key ) { 1017 1017 $result = $this->m->appendByKey( $server_key, $derived_key, $value ); 1018 1018 } else { … … 1065 1065 * @param int $expiration The expiration time, defaults to 0. 1066 1066 * @param string $server_key The key identifying the server to store the value on. 1067 * @param bool $by KeyTrue to store in internal cache by key; false to not store by key1067 * @param bool $by_key True to store in internal cache by key; false to not store by key 1068 1068 * @return bool Returns TRUE on success or FALSE on failure. 1069 1069 */ 1070 public function cas( $cas_token, $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by Key = false ) {1070 public function cas( $cas_token, $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { 1071 1071 $derived_key = $this->buildKey( $key, $group ); 1072 1072 $expiration = $this->sanitize_expiration( $expiration ); … … 1077 1077 * operation is treated as a normal "add" for no_mc_groups. 1078 1078 */ 1079 if ( in_array( $group, $this->no_mc_groups ) ) {1079 if ( in_array( $group, $this->no_mc_groups, true ) ) { 1080 1080 $this->add_to_internal_cache( $derived_key, $value ); 1081 1081 return true; … … 1083 1083 1084 1084 // Save to Memcached 1085 if ( $by Key ) {1085 if ( $by_key ) { 1086 1086 $result = $this->m->casByKey( $cas_token, $server_key, $derived_key, $value, $expiration ); 1087 1087 } else { … … 1131 1131 1132 1132 // Decrement values in no_mc_groups 1133 if ( in_array( $group, $this->no_mc_groups ) ) {1133 if ( in_array( $group, $this->no_mc_groups, true ) ) { 1134 1134 1135 1135 // Only decrement if the key already exists and value is 0 or greater (mimics memcached behavior) … … 1192 1192 * @param int $time The amount of time the server will wait to delete the item in seconds. 1193 1193 * @param string $server_key The key identifying the server to store the value on. 1194 * @param bool $by KeyTrue to store in internal cache by key; false to not store by key1194 * @param bool $by_key True to store in internal cache by key; false to not store by key 1195 1195 * @return bool Returns TRUE on success or FALSE on failure. 1196 1196 */ 1197 public function delete( $key, $group = 'default', $time = 0, $server_key = '', $by Key = false ) {1197 public function delete( $key, $group = 'default', $time = 0, $server_key = '', $by_key = false ) { 1198 1198 $derived_key = $this->buildKey( $key, $group ); 1199 1199 1200 1200 // Remove from no_mc_groups array 1201 if ( in_array( $group, $this->no_mc_groups ) ) {1201 if ( in_array( $group, $this->no_mc_groups, true ) ) { 1202 1202 if ( isset( $this->cache[ $derived_key ] ) ) { 1203 1203 unset( $this->cache[ $derived_key ] ); … … 1207 1207 } 1208 1208 1209 if ( $by Key ) {1209 if ( $by_key ) { 1210 1210 $result = $this->m->deleteByKey( $server_key, $derived_key, $time ); 1211 1211 } else { … … 1300 1300 * @param null|bool $found Variable passed by reference to determine if the value was found or not. 1301 1301 * @param string $server_key The key identifying the server to store the value on. 1302 * @param bool $by KeyTrue to store in internal cache by key; false to not store by key1302 * @param bool $by_key True to store in internal cache by key; false to not store by key 1303 1303 * @param null|callable $cache_cb Read-through caching callback. 1304 1304 * @param null|float $cas_token The variable to store the CAS token in. 1305 1305 * @return bool|mixed Cached object value. 1306 1306 */ 1307 public function get( $key, $group = 'default', $force = false, &$found = null, $server_key = '', $by Key = false, $cache_cb = null, &$cas_token = null ) {1307 public function get( $key, $group = 'default', $force = false, &$found = null, $server_key = '', $by_key = false, $cache_cb = null, &$cas_token = null ) { 1308 1308 $derived_key = $this->buildKey( $key, $group ); 1309 1309 … … 1312 1312 1313 1313 // If either $cache_db, or $cas_token is set, must hit Memcached and bypass runtime cache 1314 if ( func_num_args() > 6 && ! in_array( $group, $this->no_mc_groups ) ) {1315 if ( $by Key ) {1314 if ( func_num_args() > 6 && ! in_array( $group, $this->no_mc_groups, true ) ) { 1315 if ( $by_key ) { 1316 1316 $value = $this->m->getByKey( $server_key, $derived_key, $cache_cb, $cas_token ); 1317 1317 } else { … … 1322 1322 $found = true; 1323 1323 return is_object( $this->cache[ $derived_key ] ) ? clone $this->cache[ $derived_key ] : $this->cache[ $derived_key ]; 1324 } elseif ( in_array( $group, $this->no_mc_groups ) ) {1324 } elseif ( in_array( $group, $this->no_mc_groups, true ) ) { 1325 1325 return false; 1326 1326 } else { 1327 if ( $by Key ) {1327 if ( $by_key ) { 1328 1328 $value = $this->m->getByKey( $server_key, $derived_key ); 1329 1329 } else { … … 1465 1465 1466 1466 // If order should be preserved, reorder now 1467 if ( ! empty( $need_to_get ) && $flags === Memcached::GET_PRESERVE_ORDER) {1467 if ( ! empty( $need_to_get ) && Memcached::GET_PRESERVE_ORDER === $flags ) { 1468 1468 $ordered_values = array(); 1469 1469 … … 1604 1604 1605 1605 // Increment values in no_mc_groups 1606 if ( in_array( $group, $this->no_mc_groups ) ) {1606 if ( in_array( $group, $this->no_mc_groups, true ) ) { 1607 1607 1608 1608 // Only increment if the key already exists and the number is currently 0 or greater (mimics memcached behavior) … … 1669 1669 * @param string $group The group value prepended to the $key. 1670 1670 * @param string $server_key The key identifying the server to store the value on. 1671 * @param bool $by KeyTrue to store in internal cache by key; false to not store by key1671 * @param bool $by_key True to store in internal cache by key; false to not store by key 1672 1672 * @return bool Returns TRUE on success or FALSE on failure. 1673 1673 */ 1674 public function prepend( $key, $value, $group = 'default', $server_key = '', $by Key = false ) {1674 public function prepend( $key, $value, $group = 'default', $server_key = '', $by_key = false ) { 1675 1675 if ( ! is_string( $value ) && ! is_int( $value ) && ! is_float( $value ) ) { 1676 1676 return false; … … 1680 1680 1681 1681 // If group is a non-Memcached group, prepend to runtime cache value, not Memcached 1682 if ( in_array( $group, $this->no_mc_groups ) ) {1682 if ( in_array( $group, $this->no_mc_groups, true ) ) { 1683 1683 if ( ! isset( $this->cache[ $derived_key ] ) ) { 1684 1684 return false; … … 1691 1691 1692 1692 // Append to Memcached value 1693 if ( $by Key ) {1693 if ( $by_key ) { 1694 1694 $result = $this->m->prependByKey( $server_key, $derived_key, $value ); 1695 1695 } else { … … 1741 1741 * @param mixed $value The value to store. 1742 1742 * @param string $group The group value appended to the $key. 1743 * @param bool $by KeyTrue to store in internal cache by key; false to not store by key1743 * @param bool $by_key True to store in internal cache by key; false to not store by key 1744 1744 * @param int $expiration The expiration time, defaults to 0. 1745 1745 * @return bool Returns TRUE on success or FALSE on failure. 1746 1746 */ 1747 public function replace( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by Key = false ) {1747 public function replace( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { 1748 1748 $derived_key = $this->buildKey( $key, $group ); 1749 1749 $expiration = $this->sanitize_expiration( $expiration ); 1750 1750 1751 1751 // If group is a non-Memcached group, save to runtime cache, not Memcached 1752 if ( in_array( $group, $this->no_mc_groups ) ) {1752 if ( in_array( $group, $this->no_mc_groups, true ) ) { 1753 1753 1754 1754 // Replace won't save unless the key already exists; mimic this behavior here … … 1762 1762 1763 1763 // Save to Memcached 1764 if ( $by Key ) {1764 if ( $by_key ) { 1765 1765 $result = $this->m->replaceByKey( $server_key, $derived_key, $value, $expiration ); 1766 1766 } else { … … 1807 1807 * @param int $expiration The expiration time, defaults to 0. 1808 1808 * @param string $server_key The key identifying the server to store the value on. 1809 * @param bool $by KeyTrue to store in internal cache by key; false to not store by key1809 * @param bool $by_key True to store in internal cache by key; false to not store by key 1810 1810 * @return bool Returns TRUE on success or FALSE on failure. 1811 1811 */ 1812 public function set( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by Key = false ) {1812 public function set( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) { 1813 1813 $derived_key = $this->buildKey( $key, $group ); 1814 1814 $expiration = $this->sanitize_expiration( $expiration ); 1815 1815 1816 1816 // If group is a non-Memcached group, save to runtime cache, not Memcached 1817 if ( in_array( $group, $this->no_mc_groups ) ) {1817 if ( in_array( $group, $this->no_mc_groups, true ) ) { 1818 1818 $this->add_to_internal_cache( $derived_key, $value ); 1819 1819 return true; … … 1821 1821 1822 1822 // Save to Memcached 1823 if ( $by Key ) {1823 if ( $by_key ) { 1824 1824 $result = $this->m->setByKey( $server_key, $derived_key, $value, $expiration ); 1825 1825 } else { … … 1868 1868 * @param int $expiration The expiration time, defaults to 0. 1869 1869 * @param string $server_key The key identifying the server to store the value on. 1870 * @param bool $by KeyTrue to store in internal cache by key; false to not store by key1870 * @param bool $by_key True to store in internal cache by key; false to not store by key 1871 1871 * @return bool Returns TRUE on success or FALSE on failure. 1872 1872 */ 1873 public function setMulti( $items, $groups = 'default', $expiration = 0, $server_key = '', $by Key = false ) {1873 public function setMulti( $items, $groups = 'default', $expiration = 0, $server_key = '', $by_key = false ) { 1874 1874 // Build final keys and replace $items keys with the new keys 1875 1875 $derived_keys = $this->buildKeys( array_keys( $items ), $groups ); … … 1884 1884 1885 1885 // If group is a non-Memcached group, save to runtime cache, not Memcached 1886 if ( in_array( $key_pieces[1], $this->no_mc_groups ) ) {1886 if ( in_array( $key_pieces[1], $this->no_mc_groups, true ) ) { 1887 1887 $this->add_to_internal_cache( $derived_key, $value ); 1888 1888 unset( $derived_items[ $derived_key ] ); … … 1891 1891 1892 1892 // Save to memcached 1893 if ( $by Key ) {1893 if ( $by_key ) { 1894 1894 $result = $this->m->setMultiByKey( $server_key, $derived_items, $expiration ); 1895 1895 } else { … … 1954 1954 } 1955 1955 1956 if ( false !== array_search( $group, $this->global_groups ) ) {1956 if ( false !== array_search( $group, $this->global_groups, true ) ) { 1957 1957 $prefix = $this->global_prefix; 1958 1958 } else { … … 1992 1992 1993 1993 // If we have equal numbers of keys and groups, merge $keys[n] and $group[n] 1994 if ( count( $keys ) == count( $groups ) ) {1994 if ( count( $keys ) === count( $groups ) ) { 1995 1995 for ( $i = 0; $i < count( $keys ); $i++ ) { 1996 1996 $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[ $i ] ); … … 2002 2002 if ( isset( $groups[ $i ] ) ) { 2003 2003 $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[ $i ] ); 2004 } elseif ( count( $groups ) == 1 ) {2004 } elseif ( count( $groups ) === 1 ) { 2005 2005 $derived_keys[] = $this->buildKey( $keys[ $i ], $groups[0] ); 2006 2006 } else { … … 2047 2047 2048 2048 // Combine the values based on direction of the "pend" 2049 if ( 'pre' == $direction ) {2049 if ( 'pre' === $direction ) { 2050 2050 $combined = $pended . $original; 2051 2051 } else { … … 2081 2081 public function contains_no_mc_group( $groups ) { 2082 2082 if ( is_scalar( $groups ) ) { 2083 return in_array( $groups, $this->no_mc_groups );2083 return in_array( $groups, $this->no_mc_groups, true ); 2084 2084 } 2085 2085 … … 2089 2089 2090 2090 foreach ( $groups as $group ) { 2091 if ( in_array( $group, $this->no_mc_groups ) ) {2091 if ( in_array( $group, $this->no_mc_groups, true ) ) { 2092 2092 return true; 2093 2093 }
Note: See TracChangeset
for help on using the changeset viewer.