Make WordPress Core

Changeset 4522


Ignore:
Timestamp:
11/23/2006 05:56:53 PM (20 years ago)
Author:
matt
Message:

Caching for get_calendar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/general-template.php

    r4495 r4522  
    423423        global $wpdb, $m, $monthnum, $year, $timedifference, $wp_locale, $posts;
    424424
     425        $key = md5( $m . $monthnum . $year );
     426        if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
     427                if ( isset( $cache[ $key ] ) ) {
     428                        echo $cache;
     429                        return;
     430                }
     431        }
     432
     433        ob_start();
    425434        // Quick check. If we have no posts at all, abort!
    426435        if ( !$posts ) {
     
    472481                WHERE post_date >       '$thisyear-$thismonth-01'
    473482                AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
    474                 AND post_type = 'post' AND post_status = 'publish'
     483                AND post_type = 'post' AND post_status = 'publish' 
    475484                        ORDER   BY post_date ASC
    476485                        LIMIT 1");
     
    596605
    597606        echo "\n\t</tr>\n\t</tbody>\n\t</table>";
    598 }
     607
     608        $output = ob_get_contents();
     609        ob_end_clean();
     610        echo $output;
     611        $cache[ $key ] = $output;
     612        wp_cache_set( 'get_calendar', $cache, 'calendar' );
     613}
     614
     615function delete_get_calendar_cache() {
     616        wp_cache_delete( 'get_calendar', 'calendar' );
     617}
     618add_action( 'save_post', 'delete_get_calendar_cache' );
     619add_action( 'delete_post', 'delete_get_calendar_cache' );
     620add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
     621add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
     622add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
    599623
    600624
Note: See TracChangeset for help on using the changeset viewer.