diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
index e967503..d2ee5a0 100644
|
|
function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { |
1302 | 1302 | $term = $term->term_id; |
1303 | 1303 | if ( !$term = (int) $term ) |
1304 | 1304 | return null; |
1305 | | if ( ! $_term = wp_cache_get($term, $taxonomy) ) { |
| 1305 | if ( ! $_term = wp_cache_get($term, $taxonomy . ':terms:' . $incrementor) ) { |
1306 | 1306 | $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term) ); |
1307 | 1307 | if ( ! $_term ) |
1308 | 1308 | return null; |
diff --git tests/phpunit/tests/term/cache.php tests/phpunit/tests/term/cache.php
index b6962ce..6b4ae9c 100644
|
|
class Tests_Term_Cache extends WP_UnitTestCase { |
108 | 108 | $term = get_term_by( 'slug', 'burrito', 'post_tag' ); |
109 | 109 | $this->assertEquals( $initial, $wpdb->num_queries ); |
110 | 110 | |
111 | | $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag' ) ); |
| 111 | $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag:terms:' . wp_cache_get( 'last_changed', 'terms' ) ) ); |
112 | 112 | |
113 | 113 | $this->assertEquals( get_term( $term_id, 'post_tag' ), $term ); |
114 | 114 | $this->assertEquals( $initial, $wpdb->num_queries ); |
… |
… |
class Tests_Term_Cache extends WP_UnitTestCase { |
128 | 128 | $term = get_term_by( 'slug', 'burrito', 'post_tag' ); |
129 | 129 | $this->assertEquals( $initial, $wpdb->num_queries ); |
130 | 130 | |
131 | | $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag' ) ); |
| 131 | $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag:terms:' . wp_cache_get( 'last_changed', 'terms' ) ) ); |
132 | 132 | |
133 | 133 | wp_update_term( $term_id, 'post_tag', array( 'name' => 'Taco' ) ); |
134 | 134 | $this->assertNotEquals( $term, get_term( $term_id, 'post_tag' ) ); |
… |
… |
class Tests_Term_Cache extends WP_UnitTestCase { |
183 | 183 | $slug = 'taco'; |
184 | 184 | $name = 'Taco'; |
185 | 185 | $taxonomy = 'post_tag'; |
186 | | $cache_key_slug = 'slug:' . $slug; |
187 | | $cache_key_name = 'name:' . md5( $name ); |
| 186 | $cache_key_slug = $slug; |
| 187 | $cache_key_name = $name; |
188 | 188 | |
189 | 189 | $term_id = $this->factory->term->create( array( 'slug' => $slug, 'name' => $name, 'taxonomy' => $taxonomy ) ); |
190 | 190 | |
191 | 191 | $last_changed = wp_cache_get( 'last_changed', 'terms' ); |
192 | | $group = $taxonomy . ':' . $last_changed; |
193 | 192 | |
194 | 193 | $term = get_term_by( 'slug', $slug, $taxonomy ); |
195 | 194 | |
196 | 195 | // Verify the term is cached by ID, slug and name |
197 | | $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy ) ); |
198 | | $this->assertEquals( $term_id, wp_cache_get( $cache_key_slug, $group ) ); |
199 | | $this->assertEquals( $term_id, wp_cache_get( $cache_key_name, $group ) ); |
| 196 | $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy . ':terms:' . wp_cache_get( 'last_changed', 'terms' ) ) ); |
| 197 | $this->assertEquals( $term_id, wp_cache_get( $cache_key_slug, $taxonomy . ':slugs:' . wp_cache_get( 'last_changed', 'terms' ) ) ); |
| 198 | $this->assertEquals( $term_id, wp_cache_get( $cache_key_name, $taxonomy . ':names:' . wp_cache_get( 'last_changed', 'terms' ) ) ); |
200 | 199 | |
201 | 200 | wp_suspend_cache_invalidation(); |
202 | 201 | clean_term_cache( $term_id, $taxonomy ); |
203 | 202 | |
204 | 203 | // Verify that the cached value still matches the correct value |
205 | | $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy ) ); |
206 | | $this->assertEquals( $term_id, wp_cache_get( $cache_key_slug, $group ) ); |
207 | | $this->assertEquals( $term_id, wp_cache_get( $cache_key_name, $group ) ); |
| 204 | $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy . ':terms:' . wp_cache_get( 'last_changed', 'terms' ) ) ); |
| 205 | $this->assertEquals( $term_id, wp_cache_get( $cache_key_slug, $taxonomy . ':slugs:' . wp_cache_get( 'last_changed', 'terms' ) ) ); |
| 206 | $this->assertEquals( $term_id, wp_cache_get( $cache_key_name, $taxonomy . ':names:' . wp_cache_get( 'last_changed', 'terms' ) ) ); |
208 | 207 | |
209 | 208 | // Verify that last changed has not been updated as part of an invalidation routine |
210 | | $this->assertEquals( $last_changed, wp_get_last_changed( 'terms' ) ); |
| 209 | $this->assertEquals( $last_changed, wp_cache_get( 'last_changed', 'terms' ) ); |
211 | 210 | } |
212 | 211 | } |
| 212 | No newline at end of file |