Opened 12 years ago
Closed 12 years ago
#22560 closed defect (bug) (fixed)
Cache invalidation in wp_set_object_terms
Reported by: | batmoo | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.5 | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Taxonomy | Keywords: | has-patch commit dev-reviewed |
Focuses: | Cc: |
Description
In [21981], cache invalidation was added to wp_set_post_terms
. Should this not actually go in wp_set_object_terms
instead?
The current cache invalidation routine means that a call to wp_set_object_terms
and then a subsequent call to get_the_terms will result in stale cache entry returned.
Attachments (2)
Change History (16)
#3
@
12 years ago
The $taxonomy . '_relationships'
cache is set in get_the_terms(), which only works for posts.
So, the cache is cleared in wp_set_post_terms(), which only works for posts.
#4
follow-up:
↓ 9
@
12 years ago
- Keywords close added
I could see why this can be an issue. Many developers use wp_set_object_terms() for posts, probably not realizing the higher level function exists. I don't think there is any harm in clearing the cache at a lower point in the stack.
Correct me if I'm wrong, but this also isn't a regression? We didn't add caching, just invalidation. Or does the caching apply in new places that could cause issues?
#9
in reply to:
↑ 4
@
12 years ago
Replying to nacin:
Correct me if I'm wrong, but this also isn't a regression? We didn't add caching, just invalidation. Or does the caching apply in new places that could cause issues?
Not a regression but currently misleading since the expectation is that it's perfectly okay to use wp_set_object_terms
in place of wp_set_post_terms
and get the same outcome.
#10
@
12 years ago
- Keywords dev-feedback added
I don't think there is any harm in clearing the cache at a lower point in the stack.
I'll re-iterate my earlier statement.
#13
@
12 years ago
- Keywords has-patch commit dev-reviewed added; dev-feedback removed
If a taxonomy was assigned to completely different objects — say, a post and a user — and the same ID in both had a relationship cache, one would clear the other. This is acceptable, especially because that combination doesn't work anyway, as term relationships don't have a type of object — just an object ID and a tt ID.
Also, there is one early return in wp_set_object_terms() for db errors. We weren't doing a cache delete in wp_set_post_terms() for WP_Error either, so this also seems good.
Previous discussion that led to the change: http://core.trac.wordpress.org/ticket/21309#comment:72