Ticket #10337: 10337.12.patch

File 10337.12.patch, 1.6 KB (added by Viper007Bond, 3 years ago)

Don't use the object cache. We can't be sure it won't expire and that will require re-caching on a page load (that's bad). Always use post meta API (it has it's own object caching). Also use better cache key.

  • wp-includes/media.php

     
    10381038         * @return string The embed HTML on success, otherwise the original URL. 
    10391039         */ 
    10401040        function shortcode( $attr, $url = '' ) { 
    1041                 global $post, $_wp_using_ext_object_cache; 
     1041                global $post; 
    10421042 
    10431043                if ( empty($url) ) 
    10441044                        return ''; 
     
    10651065                if ( $post_ID ) { 
    10661066 
    10671067                        // Check for a cached result (stored in the post meta) 
    1068                         $cachekey = '_oembed_' . md5( $url . implode( '|', $attr ) ); 
     1068                        $cachekey = '_oembed_' . md5( $url . serialize( $attr ) ); 
    10691069                        if ( $this->usecache ) { 
    1070                                 $cache = ( $_wp_using_ext_object_cache ) ? wp_cache_get( "{$post_ID}_{$cachekey}", 'oembed' ) : get_post_meta( $post_ID, $cachekey, true ); 
     1070                                $cache = get_post_meta( $post_ID, $cachekey, true ); 
    10711071 
    10721072                                // Failures are cached 
    10731073                                if ( '{{unknown}}' === $cache ) 
     
    10831083 
    10841084                        // Cache the result 
    10851085                        $cache = ( $html ) ? $html : '{{unknown}}'; 
    1086                         if ( $_wp_using_ext_object_cache ) 
    1087                                 wp_cache_set( "{$post_ID}_{$cachekey}", $cache, 'oembed' ); 
    1088                         else 
    1089                                 update_post_meta( $post_ID, $cachekey, $cache ); 
     1086                        update_post_meta( $post_ID, $cachekey, $cache ); 
    10901087 
    10911088                        // If there was a result, return it 
    10921089                        if ( $html ) 
     
    11061103                $post_metas = get_post_custom_keys( $post_ID ); 
    11071104                if ( empty($post_metas) ) 
    11081105                        return; 
    1109                 foreach( (array) $post_metas as $post_meta_key ) { 
     1106 
     1107                foreach( $post_metas as $post_meta_key ) { 
    11101108                        if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) 
    11111109                                delete_post_meta( $post_ID, $post_meta_key ); 
    11121110                }