wp_using_ext_object_cache()WP 3.7.0

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.

1 time — -0.00003 sec (speed of light) | 50000 times — 0.01 sec (speed of light)

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

0

#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 );
}
0

#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() 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;
}