wp_cache_add_multiple example

if ( ! $posts ) {
        return;
    }

    $data = array();
    foreach ( $posts as $post ) {
        if ( empty( $post->filter ) || 'raw' !== $post->filter ) {
            $post = sanitize_post( $post, 'raw' );
        }
        $data[ $post->ID ] = $post;
    }
    wp_cache_add_multiple( $data, 'posts' );
}

/** * Will clean the post in the cache. * * Cleaning means delete from the cache of the post. Will call to clean the term * object cache associated with the post ID. * * This function not run if $_wp_suspend_cache_invalidation is not empty. See * wp_suspend_cache_invalidation(). * * @since 2.0.0 * * @global bool $_wp_suspend_cache_invalidation * * @param int|WP_Post $post Post ID or post object to remove from the cache. */

function update_network_cache( $networks ) {
    $data = array();
    foreach ( (array) $networks as $network ) {
        $data[ $network->id ] = $network;
    }
    wp_cache_add_multiple( $data, 'networks' );
}

/** * Adds any networks from the given IDs to the cache that do not already exist in cache. * * @since 4.6.0 * @since 6.1.0 This function is no longer marked as "private". * * @see update_network_cache() * @global wpdb $wpdb WordPress database abstraction object. * * @param array $network_ids Array of network IDs. */
            $cache[ $mpid ][ $mkey ][] = $mval;
        }
    }

    $data = array();
    foreach ( $non_cached_ids as $id ) {
        if ( ! isset( $cache[ $id ] ) ) {
            $cache[ $id ] = array();
        }
        $data[ $id ] = $cache[ $id ];
    }
    wp_cache_add_multiple( $data$cache_key );

    return $cache;
}

/** * Retrieves the queue for lazy-loading metadata. * * @since 4.5.0 * * @return WP_Metadata_Lazyloader Metadata lazyloader queue. */
return;
    }
    $site_ids          = array();
    $site_data         = array();
    $blog_details_data = array();
    foreach ( $sites as $site ) {
        $site_ids[]                                    = $site->blog_id;
        $site_data[ $site->blog_id ]                   = $site;
        $blog_details_data[ $site->blog_id . 'short' ] = $site;

    }
    wp_cache_add_multiple( $site_data, 'sites' );
    wp_cache_add_multiple( $blog_details_data, 'blog-details' );

    if ( $update_meta_cache ) {
        update_sitemeta_cache( $site_ids );
    }
}

/** * Updates metadata cache for list of site IDs. * * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache. * Subsequent calls to `get_site_meta()` will not need to query the database. * * @since 5.1.0 * * @param array $site_ids List of site IDs. * @return array|false An array of metadata on success, false if there is nothing to update. */

        }
    }

    $cache_values = array();
    foreach ( $object_terms as $id => $value ) {
        foreach ( $value as $taxonomy => $terms ) {
            $cache_values[ $taxonomy ][ $id ] = $terms;
        }
    }
    foreach ( $cache_values as $taxonomy => $data ) {
        wp_cache_add_multiple( $data, "{$taxonomy}_relationships" );
    }
}

/** * Updates terms in cache. * * @since 2.3.0 * * @param WP_Term[] $terms Array of term objects to change. * @param string $taxonomy Not used. */

function update_comment_cache( $comments$update_meta_cache = true ) {
    $data = array();
    foreach ( (array) $comments as $comment ) {
        $data[ $comment->comment_ID ] = $comment;
    }
    wp_cache_add_multiple( $data, 'comment' );

    if ( $update_meta_cache ) {
        // Avoid `wp_list_pluck()` in case `$comments` is passed by reference.         $comment_ids = array();
        foreach ( $comments as $comment ) {
            $comment_ids[] = $comment->comment_ID;
        }
        update_meta_cache( 'comment', $comment_ids );
    }
}

Home | Imprint | This part of the site doesn't use cookies.