ActionScheduler_DataController::free_memorypublic staticWC 1.0

Reduce memory footprint by clearing the database query and object caches.

Method of the class: ActionScheduler_DataController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = ActionScheduler_DataController::free_memory();

ActionScheduler_DataController::free_memory() code WC 10.6.2

public static function free_memory() {
	if ( 0 < self::$sleep_time ) {
		/* translators: %d: amount of time */
		\WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'woocommerce' ), self::$sleep_time ) );
		sleep( self::$sleep_time );
	}

	\WP_CLI::warning( __( 'Attempting to reduce used memory...', 'woocommerce' ) );

	/**
	 * Globals.
	 *
	 * @var $wpdb            \wpdb
	 * @var $wp_object_cache \WP_Object_Cache
	 */
	global $wpdb, $wp_object_cache;

	$wpdb->queries = array();

	if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) {
		return;
	}

	// Not all drop-ins support these props, however, there may be existing installations that rely on these being cleared.
	if ( property_exists( $wp_object_cache, 'group_ops' ) ) {
		$wp_object_cache->group_ops = array();
	}
	if ( property_exists( $wp_object_cache, 'stats' ) ) {
		$wp_object_cache->stats = array();
	}
	if ( property_exists( $wp_object_cache, 'memcache_debug' ) ) {
		$wp_object_cache->memcache_debug = array();
	}
	if ( property_exists( $wp_object_cache, 'cache' ) ) {
		$wp_object_cache->cache = array();
	}

	if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) {
		call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important!
	}
}