wp_using_ext_object_cache()
Checks if the plugin (additional code) for persistent object caching is enabled.
If the first parameter is specified, the function will enable/disable the tag indicating that the code/plugin object caching is used.
This function is automatically called with the parameter true at a very early stage of WP loading if the file wp-content/object-cache.php exists:
wp_using_ext_object_cache( true );
Thus, we can already check in the MU plugin, simple plugin, or Theme whether the logic of persistent object caching is used on the site.
No Hooks.
Returns
true|false. Is the additional object caching code used (enabled) on the site.
Usage
wp_using_ext_object_cache( $using );
- $using(true|false)
- Is "external" (non-default) code used for handling object cache in WordPress.
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
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 7.0
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;
}