ActionScheduler_DataController::free_memory() – Reduce memory footprint by clearing the database query and object caches.

You appear to be a bot. Output may be restricted

Description

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

Usage

ActionScheduler_DataController::free_memory();

Parameters

Returns

void

Source

File name: woocommerce/packages/action-scheduler/classes/ActionScheduler_DataController.php


Lines:

1 to 32 of 32
  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
    }
  }
 

 View on GitHub View on Trac