[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Object Cache API 4 * 5 * @link https://codex.wordpress.org/Class_Reference/WP_Object_Cache 6 * 7 * @package WordPress 8 * @subpackage Cache 9 */ 10 11 /** WP_Object_Cache class */ 12 require_once ABSPATH . WPINC . '/class-wp-object-cache.php'; 13 14 /** 15 * Adds data to the cache, if the cache key doesn't already exist. 16 * 17 * @since 2.0.0 18 * 19 * @see WP_Object_Cache::add() 20 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 21 * 22 * @param int|string $key The cache key to use for retrieval later. 23 * @param mixed $data The data to add to the cache. 24 * @param string $group Optional. The group to add the cache to. Enables the same key 25 * to be used across groups. Default empty. 26 * @param int $expire Optional. When the cache data should expire, in seconds. 27 * Default 0 (no expiration). 28 * @return bool True on success, false if cache key and group already exist. 29 */ 30 function wp_cache_add( $key, $data, $group = '', $expire = 0 ) { 31 global $wp_object_cache; 32 33 return $wp_object_cache->add( $key, $data, $group, (int) $expire ); 34 } 35 36 /** 37 * Closes the cache. 38 * 39 * This function has ceased to do anything since WordPress 2.5. The 40 * functionality was removed along with the rest of the persistent cache. 41 * 42 * This does not mean that plugins can't implement this function when they need 43 * to make sure that the cache is cleaned up after WordPress no longer needs it. 44 * 45 * @since 2.0.0 46 * 47 * @return true Always returns true. 48 */ 49 function wp_cache_close() { 50 return true; 51 } 52 53 /** 54 * Decrements numeric cache item's value. 55 * 56 * @since 3.3.0 57 * 58 * @see WP_Object_Cache::decr() 59 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 60 * 61 * @param int|string $key The cache key to decrement. 62 * @param int $offset Optional. The amount by which to decrement the item's value. Default 1. 63 * @param string $group Optional. The group the key is in. Default empty. 64 * @return int|false The item's new value on success, false on failure. 65 */ 66 function wp_cache_decr( $key, $offset = 1, $group = '' ) { 67 global $wp_object_cache; 68 69 return $wp_object_cache->decr( $key, $offset, $group ); 70 } 71 72 /** 73 * Removes the cache contents matching key and group. 74 * 75 * @since 2.0.0 76 * 77 * @see WP_Object_Cache::delete() 78 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 79 * 80 * @param int|string $key What the contents in the cache are called. 81 * @param string $group Optional. Where the cache contents are grouped. Default empty. 82 * @return bool True on successful removal, false on failure. 83 */ 84 function wp_cache_delete( $key, $group = '' ) { 85 global $wp_object_cache; 86 87 return $wp_object_cache->delete( $key, $group ); 88 } 89 90 /** 91 * Removes all cache items. 92 * 93 * @since 2.0.0 94 * 95 * @see WP_Object_Cache::flush() 96 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 97 * 98 * @return bool True on success, false on failure. 99 */ 100 function wp_cache_flush() { 101 global $wp_object_cache; 102 103 return $wp_object_cache->flush(); 104 } 105 106 /** 107 * Retrieves the cache contents from the cache by key and group. 108 * 109 * @since 2.0.0 110 * 111 * @see WP_Object_Cache::get() 112 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 113 * 114 * @param int|string $key The key under which the cache contents are stored. 115 * @param string $group Optional. Where the cache contents are grouped. Default empty. 116 * @param bool $force Optional. Whether to force an update of the local cache 117 * from the persistent cache. Default false. 118 * @param bool $found Optional. Whether the key was found in the cache (passed by reference). 119 * Disambiguates a return of false, a storable value. Default null. 120 * @return mixed|false The cache contents on success, false on failure to retrieve contents. 121 */ 122 function wp_cache_get( $key, $group = '', $force = false, &$found = null ) { 123 global $wp_object_cache; 124 125 return $wp_object_cache->get( $key, $group, $force, $found ); 126 } 127 128 /** 129 * Retrieves multiple values from the cache in one call. 130 * 131 * @since 5.5.0 132 * 133 * @see WP_Object_Cache::get_multiple() 134 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 135 * 136 * @param array $keys Array of keys under which the cache contents are stored. 137 * @param string $group Optional. Where the cache contents are grouped. Default empty. 138 * @param bool $force Optional. Whether to force an update of the local cache 139 * from the persistent cache. Default false. 140 * @return array Array of values organized into groups. 141 */ 142 function wp_cache_get_multiple( $keys, $group = '', $force = false ) { 143 global $wp_object_cache; 144 145 return $wp_object_cache->get_multiple( $keys, $group, $force ); 146 } 147 148 /** 149 * Increment numeric cache item's value 150 * 151 * @since 3.3.0 152 * 153 * @see WP_Object_Cache::incr() 154 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 155 * 156 * @param int|string $key The key for the cache contents that should be incremented. 157 * @param int $offset Optional. The amount by which to increment the item's value. Default 1. 158 * @param string $group Optional. The group the key is in. Default empty. 159 * @return int|false The item's new value on success, false on failure. 160 */ 161 function wp_cache_incr( $key, $offset = 1, $group = '' ) { 162 global $wp_object_cache; 163 164 return $wp_object_cache->incr( $key, $offset, $group ); 165 } 166 167 /** 168 * Sets up Object Cache Global and assigns it. 169 * 170 * @since 2.0.0 171 * 172 * @global WP_Object_Cache $wp_object_cache 173 */ 174 function wp_cache_init() { 175 $GLOBALS['wp_object_cache'] = new WP_Object_Cache(); 176 } 177 178 /** 179 * Replaces the contents of the cache with new data. 180 * 181 * @since 2.0.0 182 * 183 * @see WP_Object_Cache::replace() 184 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 185 * 186 * @param int|string $key The key for the cache data that should be replaced. 187 * @param mixed $data The new data to store in the cache. 188 * @param string $group Optional. The group for the cache data that should be replaced. 189 * Default empty. 190 * @param int $expire Optional. When to expire the cache contents, in seconds. 191 * Default 0 (no expiration). 192 * @return bool False if original value does not exist, true if contents were replaced 193 */ 194 function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { 195 global $wp_object_cache; 196 197 return $wp_object_cache->replace( $key, $data, $group, (int) $expire ); 198 } 199 200 /** 201 * Saves the data to the cache. 202 * 203 * Differs from wp_cache_add() and wp_cache_replace() in that it will always write data. 204 * 205 * @since 2.0.0 206 * 207 * @see WP_Object_Cache::set() 208 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 209 * 210 * @param int|string $key The cache key to use for retrieval later. 211 * @param mixed $data The contents to store in the cache. 212 * @param string $group Optional. Where to group the cache contents. Enables the same key 213 * to be used across groups. Default empty. 214 * @param int $expire Optional. When to expire the cache contents, in seconds. 215 * Default 0 (no expiration). 216 * @return bool True on success, false on failure. 217 */ 218 function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { 219 global $wp_object_cache; 220 221 return $wp_object_cache->set( $key, $data, $group, (int) $expire ); 222 } 223 224 /** 225 * Switches the internal blog ID. 226 * 227 * This changes the blog id used to create keys in blog specific groups. 228 * 229 * @since 3.5.0 230 * 231 * @see WP_Object_Cache::switch_to_blog() 232 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 233 * 234 * @param int $blog_id Site ID. 235 */ 236 function wp_cache_switch_to_blog( $blog_id ) { 237 global $wp_object_cache; 238 239 $wp_object_cache->switch_to_blog( $blog_id ); 240 } 241 242 /** 243 * Adds a group or set of groups to the list of global groups. 244 * 245 * @since 2.6.0 246 * 247 * @see WP_Object_Cache::add_global_groups() 248 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 249 * 250 * @param string|string[] $groups A group or an array of groups to add. 251 */ 252 function wp_cache_add_global_groups( $groups ) { 253 global $wp_object_cache; 254 255 $wp_object_cache->add_global_groups( $groups ); 256 } 257 258 /** 259 * Adds a group or set of groups to the list of non-persistent groups. 260 * 261 * @since 2.6.0 262 * 263 * @param string|string[] $groups A group or an array of groups to add. 264 */ 265 function wp_cache_add_non_persistent_groups( $groups ) { 266 // Default cache doesn't persist so nothing to do here. 267 } 268 269 /** 270 * Reset internal cache keys and structures. 271 * 272 * If the cache back end uses global blog or site IDs as part of its cache keys, 273 * this function instructs the back end to reset those keys and perform any cleanup 274 * since blog or site IDs have changed since cache init. 275 * 276 * This function is deprecated. Use wp_cache_switch_to_blog() instead of this 277 * function when preparing the cache for a blog switch. For clearing the cache 278 * during unit tests, consider using wp_cache_init(). wp_cache_init() is not 279 * recommended outside of unit tests as the performance penalty for using it is 280 * high. 281 * 282 * @since 2.6.0 283 * @deprecated 3.5.0 WP_Object_Cache::reset() 284 * @see WP_Object_Cache::reset() 285 * 286 * @global WP_Object_Cache $wp_object_cache Object cache global instance. 287 */ 288 function wp_cache_reset() { 289 _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Object_Cache::reset()' ); 290 291 global $wp_object_cache; 292 293 $wp_object_cache->reset(); 294 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Apr 18 01:00:12 2021 | Cross-referenced by PHPXref 0.7.1 |