Make WordPress Core

Changeset 9102


Ignore:
Timestamp:
10/08/2008 10:50:46 PM (18 years ago)
Author:
ryan
Message:

New caching style for term queries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r8944 r9102  
    610610        $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
    611611        $key = md5( serialize( compact(array_keys($defaults)) ) . serialize( $taxonomies ) . $filter_key );
    612 
    613         if ( $cache = wp_cache_get( 'get_terms', 'terms' ) ) {
    614                 if ( isset( $cache[ $key ] ) ) {
    615                         $terms = apply_filters('get_terms', $cache[$key], $taxonomies, $args);
    616                         return $terms;
    617                 }
     612        $last_changed = wp_cache_get('last_changed', 'terms');
     613        if ( !$last_changed ) {
     614                $last_changed = time();
     615                wp_cache_set('last_changed', $last_changed, 'terms');
     616        }
     617        $cache_key = "get_terms:$key:$last_changed";
     618
     619        if ( $cache = wp_cache_get( $cache_key, 'terms' ) ) {
     620                $terms = apply_filters('get_terms', $cache, $taxonomies, $args);
     621                return $terms;
    618622        }
    619623
    … …  
    747751        reset ( $terms );
    748752
    749         $cache[ $key ] = $terms;
    750         wp_cache_set( 'get_terms', $cache, 'terms' );
     753        wp_cache_add( $cache_key, $terms, 'terms' );
    751754
    752755        $terms = apply_filters('get_terms', $terms, $taxonomies, $args);
    … …  
    16991702function clean_term_cache($ids, $taxonomy = '') {
    17001703        global $wpdb;
     1704        static $cleaned = array();
    17011705
    17021706        if ( !is_array($ids) )
    … …  
    17211725
    17221726        foreach ( $taxonomies as $taxonomy ) {
     1727                if ( isset($cleaned[$taxonomy]) )
     1728                        continue;
     1729                $cleaned[$taxonomy] = true;
    17231730                wp_cache_delete('all_ids', $taxonomy);
    17241731                wp_cache_delete('get', $taxonomy);
    … …  
    17261733        }
    17271734
    1728         wp_cache_delete('get_terms', 'terms');
     1735        wp_cache_set('last_changed', time(), 'terms');
    17291736
    17301737        do_action('clean_term_cache', $ids, $taxonomy);
Note: See TracChangeset for help on using the changeset viewer.