Make WordPress Core


Ignore:
Timestamp:
02/06/2014 01:58:01 AM (11 years ago)
Author:
wonderboymusic
Message:

Regenerate the term hierarchy cache ({taxonomy}_children) when it is out of sync with the passed taxonomy's last_changed value.

Introduces taxonomy_hierarchy_is_fresh(), which is only called in _get_term_hierarchy(). The taxonomy's last_changed value is checked against the value of wp_cache_get( 'hierarchy_last_changed', $taxonomy ).

Adds a unit test - Tests_Term:test_hierachy_invalidation().

See [27101], which makes this type of cache invalidation possible.
Fixes #14485.

File:
1 edited

Legend:

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

    r27101 r27102  
    29492949    if ( !is_taxonomy_hierarchical($taxonomy) )
    29502950        return array();
    2951     $children = get_option("{$taxonomy}_children");
     2951    $children = false;
     2952    if ( taxonomy_hierarchy_is_fresh( $taxonomy ) ) {
     2953        $children = get_option("{$taxonomy}_children");
     2954    }
    29522955
    29532956    if ( is_array($children) )
     
    35223525 * Determine if a post's cache for the passed taxonomy
    35233526 *  is in sync.
     3527 *
    35243528 * @since 3.9.0
    35253529 *
     
    35373541    return true;
    35383542}
     3543
     3544/**
     3545 * Determine if a hierarchy's cache for the passed taxonomy
     3546 *  is in sync.
     3547 *
     3548 * @since 3.9.0
     3549 *
     3550 * @param int $id
     3551 * @param string $taxonomy
     3552 * @return boolean
     3553 */
     3554function taxonomy_hierarchy_is_fresh( $taxonomy ) {
     3555    $last_changed = get_taxonomy_last_changed( $taxonomy );
     3556    $hierarchy_last_changed = wp_cache_get( 'hierarchy_last_changed', $taxonomy );
     3557    if ( ! $hierarchy_last_changed || $last_changed !== $hierarchy_last_changed ) {
     3558        wp_cache_set( 'hierarchy_last_changed', $last_changed, $taxonomy );
     3559        return false;
     3560    }
     3561    return true;
     3562}
Note: See TracChangeset for help on using the changeset viewer.