Make WordPress Core

Ticket #22526: 22526.3.diff

File 22526.3.diff, 3.0 KB (added by wonderboymusic, 11 years ago)
  • src/wp-includes/taxonomy.php

     
    35163516 * @return int Unix timestamp with microseconds of the last taxonomy change.
    35173517 */
    35183518function get_taxonomy_last_changed( $taxonomy ) {
    3519         $last_changed = wp_cache_get( 'last_changed', $taxonomy );
     3519        $key = $taxonomy . '_last_changed';
     3520        $last_changed = wp_cache_get( $key, 'terms' );
    35203521        if ( ! $last_changed ) {
    35213522                $last_changed = microtime();
    3522                 wp_cache_set( 'last_changed', $last_changed, $taxonomy );
     3523                wp_cache_delete( $key, 'terms' );
     3524                wp_cache_add( $key, $last_changed, 'terms' );
    35233525        }
    35243526        return $last_changed;
    35253527}
     
    35333535 * @return int Unix timestamp with microseconds of the last taxonomy change.
    35343536 */
    35353537function set_taxonomy_last_changed( $taxonomy ) {
    3536         wp_cache_delete( 'last_changed', $taxonomy );
     3538        wp_cache_delete( $taxonomy . '_last_changed', 'terms' );
    35373539        return get_taxonomy_last_changed( $taxonomy );
    35383540}
    35393541
     
    35533555 */
    35543556function post_taxonomy_is_fresh( $id, $taxonomy ) {
    35553557        $last_changed = get_taxonomy_last_changed( $taxonomy );
    3556         $post_last_changed = wp_cache_get( $id, $taxonomy . '_last_changed' );
     3558        $key = $id . '_' . $taxonomy . '_last_changed';
     3559        $post_last_changed = wp_cache_get( $key, 'terms' );
    35573560        if ( ! $post_last_changed || $last_changed !== $post_last_changed ) {
    3558                 wp_cache_set( $id, $last_changed, $taxonomy . '_last_changed' );
     3561                wp_cache_delete( $key, 'terms' );
     3562                wp_cache_add( $key, $last_changed, 'terms' );
    35593563                return false;
    35603564        }
    35613565        return true;
     
    35773581 */
    35783582function taxonomy_hierarchy_is_fresh( $taxonomy ) {
    35793583        $last_changed = get_taxonomy_last_changed( $taxonomy );
    3580         $hierarchy_last_changed = wp_cache_get( 'hierarchy_last_changed', $taxonomy );
     3584        $key = $taxonomy . '_hierarchy_last_changed';
     3585        $hierarchy_last_changed = wp_cache_get( $key, 'terms' );
    35813586        if ( ! $hierarchy_last_changed || $last_changed !== $hierarchy_last_changed ) {
    3582                 wp_cache_set( 'hierarchy_last_changed', $last_changed, $taxonomy );
     3587                wp_cache_delete( $key, 'terms' );
     3588                wp_cache_add( $key, $last_changed, 'terms' );
    35833589                return false;
    35843590        }
    35853591        return true;
  • tests/phpunit/tests/term/cache.php

     
    3434         */
    3535        function test_get_taxonomy_last_changed() {
    3636                $last_changed = get_taxonomy_last_changed( 'category' );
    37                 $last_changed_cache = wp_cache_get( 'last_changed', 'category' );
     37                $key = 'category_last_changed';
     38                $last_changed_cache = wp_cache_get( $key, 'terms' );
    3839                $this->assertEquals( $last_changed, $last_changed_cache );
    39                 wp_cache_delete( 'last_changed', 'category' );
     40                wp_cache_delete( $key, 'terms' );
    4041                $this->assertEquals( $last_changed, $last_changed_cache );
    4142                $last_changed = get_taxonomy_last_changed( 'category' );
    4243                $this->assertNotEquals( $last_changed, $last_changed_cache );