Changeset 47197 for trunk/src/wp-includes/class-wp-object-cache.php
- Timestamp:
- 02/06/2020 05:51:58 AM (5 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-object-cache.php
r47196 r47197 1 1 <?php 2 2 /** 3 * Object Cache API 4 * 5 * @link https://codex.wordpress.org/Class_Reference/WP_Object_Cache 3 * Object Cache API: WP_Object_Cache class 6 4 * 7 5 * @package WordPress 8 6 * @subpackage Cache 7 * @since 5.4.0 9 8 */ 10 11 /**12 * Adds data to the cache, if the cache key doesn't already exist.13 *14 * @since 2.0.015 *16 * @see WP_Object_Cache::add()17 * @global WP_Object_Cache $wp_object_cache Object cache global instance.18 *19 * @param int|string $key The cache key to use for retrieval later.20 * @param mixed $data The data to add to the cache.21 * @param string $group Optional. The group to add the cache to. Enables the same key22 * to be used across groups. Default empty.23 * @param int $expire Optional. When the cache data should expire, in seconds.24 * Default 0 (no expiration).25 * @return bool True on success, false if cache key and group already exist.26 */27 function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {28 global $wp_object_cache;29 30 return $wp_object_cache->add( $key, $data, $group, (int) $expire );31 }32 33 /**34 * Closes the cache.35 *36 * This function has ceased to do anything since WordPress 2.5. The37 * functionality was removed along with the rest of the persistent cache.38 *39 * This does not mean that plugins can't implement this function when they need40 * to make sure that the cache is cleaned up after WordPress no longer needs it.41 *42 * @since 2.0.043 *44 * @return true Always returns true.45 */46 function wp_cache_close() {47 return true;48 }49 50 /**51 * Decrements numeric cache item's value.52 *53 * @since 3.3.054 *55 * @see WP_Object_Cache::decr()56 * @global WP_Object_Cache $wp_object_cache Object cache global instance.57 *58 * @param int|string $key The cache key to decrement.59 * @param int $offset Optional. The amount by which to decrement the item's value. Default 1.60 * @param string $group Optional. The group the key is in. Default empty.61 * @return int|false The item's new value on success, false on failure.62 */63 function wp_cache_decr( $key, $offset = 1, $group = '' ) {64 global $wp_object_cache;65 66 return $wp_object_cache->decr( $key, $offset, $group );67 }68 69 /**70 * Removes the cache contents matching key and group.71 *72 * @since 2.0.073 *74 * @see WP_Object_Cache::delete()75 * @global WP_Object_Cache $wp_object_cache Object cache global instance.76 *77 * @param int|string $key What the contents in the cache are called.78 * @param string $group Optional. Where the cache contents are grouped. Default empty.79 * @return bool True on successful removal, false on failure.80 */81 function wp_cache_delete( $key, $group = '' ) {82 global $wp_object_cache;83 84 return $wp_object_cache->delete( $key, $group );85 }86 87 /**88 * Removes all cache items.89 *90 * @since 2.0.091 *92 * @see WP_Object_Cache::flush()93 * @global WP_Object_Cache $wp_object_cache Object cache global instance.94 *95 * @return bool True on success, false on failure.96 */97 function wp_cache_flush() {98 global $wp_object_cache;99 100 return $wp_object_cache->flush();101 }102 103 /**104 * Retrieves the cache contents from the cache by key and group.105 *106 * @since 2.0.0107 *108 * @see WP_Object_Cache::get()109 * @global WP_Object_Cache $wp_object_cache Object cache global instance.110 *111 * @param int|string $key The key under which the cache contents are stored.112 * @param string $group Optional. Where the cache contents are grouped. Default empty.113 * @param bool $force Optional. Whether to force an update of the local cache from the persistent114 * cache. Default false.115 * @param bool $found Optional. Whether the key was found in the cache (passed by reference).116 * Disambiguates a return of false, a storable value. Default null.117 * @return bool|mixed False on failure to retrieve contents or the cache118 * contents on success119 */120 function wp_cache_get( $key, $group = '', $force = false, &$found = null ) {121 global $wp_object_cache;122 123 return $wp_object_cache->get( $key, $group, $force, $found );124 }125 126 /**127 * Increment numeric cache item's value128 *129 * @since 3.3.0130 *131 * @see WP_Object_Cache::incr()132 * @global WP_Object_Cache $wp_object_cache Object cache global instance.133 *134 * @param int|string $key The key for the cache contents that should be incremented.135 * @param int $offset Optional. The amount by which to increment the item's value. Default 1.136 * @param string $group Optional. The group the key is in. Default empty.137 * @return int|false The item's new value on success, false on failure.138 */139 function wp_cache_incr( $key, $offset = 1, $group = '' ) {140 global $wp_object_cache;141 142 return $wp_object_cache->incr( $key, $offset, $group );143 }144 145 /**146 * Sets up Object Cache Global and assigns it.147 *148 * @since 2.0.0149 *150 * @global WP_Object_Cache $wp_object_cache151 */152 function wp_cache_init() {153 $GLOBALS['wp_object_cache'] = new WP_Object_Cache();154 }155 156 /**157 * Replaces the contents of the cache with new data.158 *159 * @since 2.0.0160 *161 * @see WP_Object_Cache::replace()162 * @global WP_Object_Cache $wp_object_cache Object cache global instance.163 *164 * @param int|string $key The key for the cache data that should be replaced.165 * @param mixed $data The new data to store in the cache.166 * @param string $group Optional. The group for the cache data that should be replaced.167 * Default empty.168 * @param int $expire Optional. When to expire the cache contents, in seconds.169 * Default 0 (no expiration).170 * @return bool False if original value does not exist, true if contents were replaced171 */172 function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) {173 global $wp_object_cache;174 175 return $wp_object_cache->replace( $key, $data, $group, (int) $expire );176 }177 178 /**179 * Saves the data to the cache.180 *181 * Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.182 *183 * @since 2.0.0184 *185 * @see WP_Object_Cache::set()186 * @global WP_Object_Cache $wp_object_cache Object cache global instance.187 *188 * @param int|string $key The cache key to use for retrieval later.189 * @param mixed $data The contents to store in the cache.190 * @param string $group Optional. Where to group the cache contents. Enables the same key191 * to be used across groups. Default empty.192 * @param int $expire Optional. When to expire the cache contents, in seconds.193 * Default 0 (no expiration).194 * @return bool True on success, false on failure.195 */196 function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {197 global $wp_object_cache;198 199 return $wp_object_cache->set( $key, $data, $group, (int) $expire );200 }201 202 /**203 * Switches the internal blog ID.204 *205 * This changes the blog id used to create keys in blog specific groups.206 *207 * @since 3.5.0208 *209 * @see WP_Object_Cache::switch_to_blog()210 * @global WP_Object_Cache $wp_object_cache Object cache global instance.211 *212 * @param int $blog_id Site ID.213 */214 function wp_cache_switch_to_blog( $blog_id ) {215 global $wp_object_cache;216 217 $wp_object_cache->switch_to_blog( $blog_id );218 }219 220 /**221 * Adds a group or set of groups to the list of global groups.222 *223 * @since 2.6.0224 *225 * @see WP_Object_Cache::add_global_groups()226 * @global WP_Object_Cache $wp_object_cache Object cache global instance.227 *228 * @param string|array $groups A group or an array of groups to add.229 */230 function wp_cache_add_global_groups( $groups ) {231 global $wp_object_cache;232 233 $wp_object_cache->add_global_groups( $groups );234 }235 236 /**237 * Adds a group or set of groups to the list of non-persistent groups.238 *239 * @since 2.6.0240 *241 * @param string|array $groups A group or an array of groups to add.242 */243 function wp_cache_add_non_persistent_groups( $groups ) {244 // Default cache doesn't persist so nothing to do here.245 }246 247 /**248 * Reset internal cache keys and structures.249 *250 * If the cache back end uses global blog or site IDs as part of its cache keys,251 * this function instructs the back end to reset those keys and perform any cleanup252 * since blog or site IDs have changed since cache init.253 *254 * This function is deprecated. Use wp_cache_switch_to_blog() instead of this255 * function when preparing the cache for a blog switch. For clearing the cache256 * during unit tests, consider using wp_cache_init(). wp_cache_init() is not257 * recommended outside of unit tests as the performance penalty for using it is258 * high.259 *260 * @since 2.6.0261 * @deprecated 3.5.0 WP_Object_Cache::reset()262 * @see WP_Object_Cache::reset()263 *264 * @global WP_Object_Cache $wp_object_cache Object cache global instance.265 */266 function wp_cache_reset() {267 _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Object_Cache::reset()' );268 269 global $wp_object_cache;270 271 $wp_object_cache->reset();272 }273 9 274 10 /**
Note: See TracChangeset
for help on using the changeset viewer.