wp_cache_replace()
Replaces the contents of the cache with new data.
1 time — 0.00012 sec (fast) | 50000 times — 1.23 sec (fast)
No Hooks.
Return
true|false
. True if contents were replaced, false if original value does not exist.
Usage
wp_cache_replace( $key, $data, $group, $expire );
- $key(int|string) (required)
- The key for the cache data that should be replaced.
- $data(mixed) (required)
- The new data to store in the cache.
- $group(string)
- The group for the cache data that should be replaced.
Default: '' - $expire(int)
- When to expire the cache contents, in seconds.
Default: 0 (no expiration)
Examples
#1 Usage Example
$main_authors = array( getuserdata(1), get_userdata(10), get_userdata(7) ); $replaced = wp_cache_replace('main_authors', $main_authors, 'authors' ); if( $replaced ){ echo 'Done! The data has been replaced.'; } else { echo 'Can`t replace the cache because it doesn't exist yet.'; }
Notes
- See: WP_Object_Cache::replace()
- Global. WP_Object_Cache. $wp_object_cache Object cache global instance.
Changelog
Since 2.0.0 | Introduced. |
wp_cache_replace() wp cache replace code WP 6.7.1
function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { global $wp_object_cache; return $wp_object_cache->replace( $key, $data, $group, (int) $expire ); }