Make WordPress Core

Ticket #45471: cache-key.patch

File cache-key.patch, 1.1 KB (added by joostdevalk, 6 years ago)

Cache key patch

  • wp-includes/blocks.php

     
    210210 *
    211211 * @since 5.0.0
    212212 *
    213  * @param string $content Post content.
     213 * @param string      $content   Post content.
     214 * @param string|bool $cache_key The cache key to use for the parsed blocks.
     215 *
    214216 * @return array Array of parsed block objects.
    215217 */
    216 function parse_blocks( $content ) {
     218function parse_blocks( $content, $cache_key = false ) {
     219        if ( $cache_key ) {
     220                $parse_result = wp_cache_get( $cache_key, 'parsed_blocks' );
     221                if ( $parse_result ) {
     222                        return $parse_result;
     223                }
     224        }
     225
    217226        /**
    218227         * Filter to allow plugins to replace the server-side block parser
    219228         *
     
    224233        $parser_class = apply_filters( 'block_parser_class', 'WP_Block_Parser' );
    225234
    226235        $parser = new $parser_class();
    227         return $parser->parse( $content );
     236        $parse_result = $parser->parse( $content );
     237        if ( $cache_key ) {
     238                wp_cache_add( $cache_key, $parse_result,'parsed_blocks' );
     239        }
     240        return $parse_result;
    228241}
    229242
    230243/**