Ticket #22526: 22526.3.diff
File 22526.3.diff, 3.0 KB (added by , 11 years ago) |
---|
-
src/wp-includes/taxonomy.php
3516 3516 * @return int Unix timestamp with microseconds of the last taxonomy change. 3517 3517 */ 3518 3518 function 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' ); 3520 3521 if ( ! $last_changed ) { 3521 3522 $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' ); 3523 3525 } 3524 3526 return $last_changed; 3525 3527 } … … 3533 3535 * @return int Unix timestamp with microseconds of the last taxonomy change. 3534 3536 */ 3535 3537 function set_taxonomy_last_changed( $taxonomy ) { 3536 wp_cache_delete( 'last_changed', $taxonomy);3538 wp_cache_delete( $taxonomy . '_last_changed', 'terms' ); 3537 3539 return get_taxonomy_last_changed( $taxonomy ); 3538 3540 } 3539 3541 … … 3553 3555 */ 3554 3556 function post_taxonomy_is_fresh( $id, $taxonomy ) { 3555 3557 $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' ); 3557 3560 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' ); 3559 3563 return false; 3560 3564 } 3561 3565 return true; … … 3577 3581 */ 3578 3582 function taxonomy_hierarchy_is_fresh( $taxonomy ) { 3579 3583 $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' ); 3581 3586 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' ); 3583 3589 return false; 3584 3590 } 3585 3591 return true; -
tests/phpunit/tests/term/cache.php
34 34 */ 35 35 function test_get_taxonomy_last_changed() { 36 36 $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' ); 38 39 $this->assertEquals( $last_changed, $last_changed_cache ); 39 wp_cache_delete( 'last_changed', 'category' );40 wp_cache_delete( $key, 'terms' ); 40 41 $this->assertEquals( $last_changed, $last_changed_cache ); 41 42 $last_changed = get_taxonomy_last_changed( 'category' ); 42 43 $this->assertNotEquals( $last_changed, $last_changed_cache );