ActionScheduler_DataController::free_memory()public staticWC 1.0

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

Метод класса: ActionScheduler_DataController{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$result = ActionScheduler_DataController::free_memory();

Код ActionScheduler_DataController::free_memory() WC 8.7.0

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' ) );

	/**
	 * @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;
	}

	$wp_object_cache->group_ops      = array();
	$wp_object_cache->stats          = array();
	$wp_object_cache->memcache_debug = array();
	$wp_object_cache->cache          = array();

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