wp_using_ext_object_cache()
Toggle $_wp_using_ext_object_cache on and off without directly touching global.
Used By: set_site_transient(), wp_cache_flush_runtime()
1 time — -0.00003 sec (speed of light) | 50000 times — 0.01 sec (speed of light)
No Hooks.
Return
true|false
. The current 'using' setting.
Usage
wp_using_ext_object_cache( $using );
- $using(true|false)
- Whether external object cache is being used.
Default: null
Examples
#1 Cache data in the object cache, only if it enabled
This example shows how, for example, in a plugin you can check whether site uses persistent object caching. And if it is used, add some data to the object cache.
if ( wp_using_ext_object_cache() ) { // add data to the cache wp_cache_set( $cache_key, $value ); }
#2 Check if the persistent object cache is enabled on the site [auto-translate]
var_dump( wp_using_ext_object_cache() ); // bool(true)
Notes
- Global. true|false. $_wp_using_ext_object_cache
Changelog
Since 3.7.0 | Introduced. |
wp_using_ext_object_cache() wp using ext object cache code WP 6.6.2
function wp_using_ext_object_cache( $using = null ) { global $_wp_using_ext_object_cache; $current_using = $_wp_using_ext_object_cache; if ( null !== $using ) { $_wp_using_ext_object_cache = $using; } return $current_using; }