Make WordPress Core

Ticket #22301: 22301.diff

File 22301.diff, 1.6 KB (added by pento, 11 years ago)
  • src/wp-includes/default-widgets.php

     
    811811        }
    812812
    813813        public function flush_widget_cache() {
    814                 wp_cache_delete('widget_recent_comments', 'widget');
     814                $cache = wp_cache_get( 'widget_recent_comments', 'widget' );
     815                if ( ! empty( $cache ) ) {
     816                        // If the cache is flushed multiple times, we don't want to save an empty copy
     817                        wp_cache_delete( 'widget_recent_comments', 'widget' );
     818                        wp_cache_set( 'widget_recent_comments_old', $cache, 'widget' );
     819                }
    815820        }
    816821
    817822        public function widget( $args, $instance ) {
    818823                global $comments, $comment;
    819824
    820825                $cache = array();
     826                $cache_lock = false;
    821827                if ( ! $this->is_preview() ) {
    822                         $cache = wp_cache_get('widget_recent_comments', 'widget');
     828                        $cache = wp_cache_get( 'widget_recent_comments', 'widget' );
     829                        if ( empty( $cache ) ) {
     830                                // The cache has been deleted. Grab the old copy (if it exists),
     831                                // and try to get the update lock
     832                                $cache = wp_cache_get( 'widget_recent_comments_old', 'widget' );
     833                                $cache_lock = wp_cache_add( 'widget_recent_comments_lock', 1, 'widget' );
     834                        }
    823835                }
    824836                if ( ! is_array( $cache ) ) {
    825837                        $cache = array();
     
    885897
    886898                echo $output;
    887899
    888                 if ( ! $this->is_preview() ) {
     900                if ( ! $this->is_preview() && $cache_lock ) {
    889901                        $cache[ $args['widget_id'] ] = $output;
    890902                        wp_cache_set( 'widget_recent_comments', $cache, 'widget' );
     903                        wp_cache_delete( 'widget_recent_comments_lock', 'widget' );
    891904                }
    892905        }
    893906