[wp-trac] [WordPress Trac] #40306: Term cache isn't cleared completely when setting and removing object terms

WordPress Trac noreply at wordpress.org
Wed Mar 29 18:52:43 UTC 2017


#40306: Term cache isn't cleared completely when setting and removing object terms
--------------------------+-----------------------------
 Reporter:  mboynes       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 This problem is easiest explained and understood through a unit test; see
 attached for that plus the patch fixing it.

 `wp_set_object_terms()` and `wp_remove_object_terms()` delete the object
 cache entry for the object ID in the group `{$taxonomy}_relationships`.
 However, `Term_Query`, which ultimately queries for those terms, has its
 own cache that doesn't get invalidated.`Term_Query`'s cache key depends on
 the `terms:last_changed` cache entry, so deleting that cache entry will
 invalidate the cache.

 This could/should be a bigger issue than it actually is. The reason it
 isn't is that the cache gets cleared incidentally via
 `wp_update_term_count_now()`, which performs
 [https://core.trac.wordpress.org/browser/tags/4.7.3/src/wp-
 includes/taxonomy.php#L2891 a pretty greedy cache clear]. If one is using
 an external object cache and disables term counting, the term relationship
 gets set when the default empty post is created on the "Write" screen and
 is never erased, and it will forever appear as though a post has no terms
 (until some other operation invalidates the `Term_Query` cache).

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40306>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list