Ticket #22301: 22301.diff
File 22301.diff, 1.6 KB (added by , 11 years ago) |
---|
-
src/wp-includes/default-widgets.php
811 811 } 812 812 813 813 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 } 815 820 } 816 821 817 822 public function widget( $args, $instance ) { 818 823 global $comments, $comment; 819 824 820 825 $cache = array(); 826 $cache_lock = false; 821 827 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 } 823 835 } 824 836 if ( ! is_array( $cache ) ) { 825 837 $cache = array(); … … 885 897 886 898 echo $output; 887 899 888 if ( ! $this->is_preview() ) {900 if ( ! $this->is_preview() && $cache_lock ) { 889 901 $cache[ $args['widget_id'] ] = $output; 890 902 wp_cache_set( 'widget_recent_comments', $cache, 'widget' ); 903 wp_cache_delete( 'widget_recent_comments_lock', 'widget' ); 891 904 } 892 905 } 893 906